android 对gridview 外层linearlayout 设置点击事件,怎么还点到gridview(gridview没点击事件)?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 对gridview 外层linearlayout 设置点击事件,怎么还点到gridview(gridview没点击事件)?相关的知识,希望对你有一定的参考价值。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/selector">
<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="8dip"
android:numColumns="8"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:stretchMode="spacingWidthUniform"
android:gravity="center"/>
</LinearLayout>
android gridview几个重要属性
if (mSelector != null) {
mSelector.setCallback(null);
unscheduleDrawable(mSelector);
}
mSelector = sel;
Rect padding = new Rect();
sel.getPadding(padding);
mSelectionLeftPadding = padding.left;
mSelectionTopPadding = padding.top;
mSelectionRightPadding = padding.right;
mSelectionBottomPadding = padding.bottom;
sel.setCallback(this);
updateSelectorState();
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mSelector == null) {
useDefaultSelector();
}
final Rect listPadding = mListPadding;
listPadding.left = mSelectionLeftPadding + mPaddingLeft;
listPadding.top = mSelectionTopPadding + mPaddingTop;
listPadding.right = mSelectionRightPadding + mPaddingRight;
listPadding.bottom = mSelectionBottomPadding + mPaddingBottom;
final int columnWidth = mColumnWidth;
final int horizontalSpacing = mHorizontalSpacing;
final boolean isLayoutRtl = isLayoutRtl();
int last;
int nextLeft;
if (isLayoutRtl) {
nextLeft = getWidth() - mListPadding.right - columnWidth -
((mStretchMode == STRETCH_SPACING_UNIFORM) ? horizontalSpacing : 0);
} else {
nextLeft = mListPadding.left +
((mStretchMode == STRETCH_SPACING_UNIFORM) ? horizontalSpacing : 0);
} // 这里累加了,顺便可以看到spacingWidthUniform熟悉的作用
if (!mStackFromBottom) {
last = Math.min(startPos + mNumColumns, mItemCount);
} else {
last = startPos + 1;
startPos = Math.max(0, startPos - mNumColumns + 1);
if (last - startPos < mNumColumns) {
final int deltaLeft = (mNumColumns - (last - startPos)) * (columnWidth + horizontalSpacing);
nextLeft += (isLayoutRtl ? -1 : +1) * deltaLeft;
}
}
以上是关于android 对gridview 外层linearlayout 设置点击事件,怎么还点到gridview(gridview没点击事件)?的主要内容,如果未能解决你的问题,请参考以下文章
android 不居中界面限制了控件个数,控件太多就满了怎么办,附图,最后一行
android gridview 怎么在适配器中设置不可选择项
Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!