GridView的奇怪输出

时间:2013-09-17 11:15:47

标签: android android-layout android-gridview

使用以下代码我得到一些意想不到的输出:

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已经开始了某种彩票;还是有合理的解释?

0 个答案:

没有答案