GridView 自动调整图像 [英] GridView auto fit images
问题描述
我试图在 GridView 中显示图像并自动设置列,到目前为止我不得不手动设置列数,这不是我想要做的,因为这会影响图像的大小不同尺寸的屏幕.我试过将它设置为 auto_fit 但它只在屏幕中间显示 2 列.这就是我想要实现的:(每个红色方块代表一个图像)
im trying to get images displayed in a GridView and get the columns automatically set, so far I've had to manually set the number of columns which is not what i want to do as this will affect how big the images are on different sized screens. I ahve tried setting it to auto_fit but it only displays 2 columns in the middle of the screen. This is what im trying to achieve: (Each red square represents an image)
然后当转向横向模式时,我希望列自动适应,以便它全部均匀.任何帮助将不胜感激,谢谢:)
then when turned to landscape mode i want the columns to auto fit so that its all even. Any help would be much appreciated, thank you :)
推荐答案
使用 GridView 属性进行实验,特别是 android:numColumns="auto_fit"
和 android:stretchMode
.以下对我有用:
Experiment with the GridView attributes, specifically android:numColumns="auto_fit"
and android:stretchMode
. The following works for me:
<GridView
android:id="@+id/myGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
这篇关于GridView 自动调整图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!