定製gridview使其在listview中當作item使用

銳湃發表於2015-12-10

改定其onMeasure方法

程式碼如下:

public class ActorGridView extends GridView {
	
	public ActorGridView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public ActorGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public ActorGridView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
	}
	
	
	@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

}


相關文章