动态改变的android gridview的列数? [英] Dynamically change column number in android gridview?
问题描述
我的应用程序中显示,我使用XML作为
My application display the image icon in gridview in landscape orientation.For that i use the xml as
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="4"
android:columnWidth="100px"
android:stretchMode="columnWidth"
android:gravity="center"/>
有关纵向我想只显示在GridView控件column.How两个图像图标做到这一点?
For portrait orientation i want to display only two image icon in gridview column.How to do it?.
推荐答案
通过使用自适应资源:确保在资源文件夹 / RES
您有以下文件夹:值陆
和值端口
。在这两个文件夹中添加一个资源文件,姑且称之为integers.xml。
By using adaptive resources: make sure in resources folder /res
you have the following folders: values-land
and values-port
. In both of those folders add a resource file, let's call it integers.xml.
在 /values-land/integers.xml 的你将至少有:
<resources>
<item name="grid_rows" type="integer">4</item>
</resources>
而对值端口/ integers.xml 的:
<resources>
<item name="grid_rows" type="integer">3</item>
</resources>
布局更改为:
The layout changes to:
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100px"
android:gravity="center"
android:numColumns="@integer/grid_rows"
android:stretchMode="columnWidth" />
请注意的presence @整数/ grid_rows
Note the presence of @integer/grid_rows
这篇关于动态改变的android gridview的列数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!