使用以下代码,我得到了一些意外的输出:
Log.i(TAG, "Activity numColumns: "+mGrid.getNumColumns());
Log.i(TAG, "Activity verticalSpace: "+mGrid.getVerticalSpacing());
Log.i(TAG, "Activity horizontalSpace: "+mGrid.getHorizontalSpacing());
日志输出说:
09-17 10:39:26.083: I/MeMoGame(744):Activity numColumns: -1
09-17 10:39:26.083: I/MeMoGame(744):Activity verticalSpace: 7
09-17 10:39:26.083: I/MeMoGame(744): Activity horizontalSpace: 0
这很奇怪,因为这些是在 XML 中输入的值:
<GridView
android:id="@+id/gridView"
android:horizontalSpacing="@dimen/grid_horizontal_space"
android:verticalSpacing="@dimen/grid_vertical_space"
android:numColumns="4"
和:
<dimen
name="grid_horizontal_space">7dp</dimen>
<dimen
name="grid_vertical_space">7dp</dimen>
看起来Android已经开始了某种彩票;还是有合理的解释?