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
把你的代碼....你在哪裏設置監聽器。 –