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"/>
For portrait orientation i want to display only two image icon in gridview column.How to do it?.
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.
In /values-land/integers.xml you will have at least:
<resources>
<item name="grid_rows" type="integer">4</item>
</resources>
while for values-port/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" />
Note the presence of @integer/grid_rows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With