GridView控件自动调整图像 [英] GridView auto fit images

查看:151
本文介绍了GridView控件自动调整图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去得到一个GridView显示的图像,并获得自动设置列,到目前为止,我不得不手动设置列的数量,这是不是我想要做的,因为这会影响到图像有多大的不同大小的屏幕。我ahve试图把它置auto_fit但它只是在屏幕中间显示2列。这是我尝试实现:(每红场再presents图像)

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)

那么当转向横向模式我想列自动调整,使所有的偶数。 任何帮助将是非常美联社preciated,谢谢:)

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控件的属性,特别是机器人:为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆