GridView
由于其占用行的大部分空间,所以它的父母(ListView
)变得不可触及。 您需要使GridView
不可滚动。它可以通过扩展GridView
和ovveriding onMeasure方法做
public class NonScrollableGridView extends GridView {
public NonScrollableGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Do not use the highest two bits of Integer.MAX_VALUE because they are
// reserved for the MeasureSpec mode
int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightSpec);
getLayoutParams().height = getMeasuredHeight();
}
}
另一种选择是使用RecyclerView
与GridLayoutManager
insted的的ListView
,然后不使用GridView
把你的代码....你在哪里设置监听器。 –