Skip to content

Instantly share code, notes, and snippets.

@fdoyle
Created September 5, 2014 14:32
Show Gist options
  • Save fdoyle/024ff17b6550b4acf9ad to your computer and use it in GitHub Desktop.
Save fdoyle/024ff17b6550b4acf9ad to your computer and use it in GitHub Desktop.
a thing that doesn't render the top N pixels of a listview.
package com.derp.android
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.widget.ListView;
/**
* Created by fdoyle on 9/4/14.
*/
public class TopClippingListView extends ListView {
Paint clearPaint = new Paint();
int clipHeight = 0;
public TopClippingListView(Context context) {
super(context);
init();
}
public TopClippingListView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public TopClippingListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public void setClipHeight(int newHeight) {
clipHeight = newHeight;
}
public void init() {
setLayerType(LAYER_TYPE_SOFTWARE, new Paint());
clearPaint.setAlpha(0xFF);
clearPaint.setXfermode(new PorterDuffXfermode(
PorterDuff.Mode.CLEAR));
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
canvas.drawRect(0, 0, getWidth(), clipHeight, clearPaint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment