public class HFGridView extends GridView { public HFGridView(Context context) { super(context); } public HFGridView(Context context, AttributeSet attrs) { super(context, attrs); } public HFGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
Layout使用
<YourPackageName.HFGridView android:id="@+id/gv_use" style="@style/search_grid_view" android:numColumns="4" />
程式內宣告使用
HFGridView gv = (HFGridView) findViewById(R.id.gv_use); gv.setOnItemClickListener(new GridView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //do something } });
沒有留言:
張貼留言