简体   繁体   English

GridView行高

[英]GridView row height

I have a GridView that displays images, which are, unfortunately, of different sizes. 我有一个显示图像的GridView,不幸的是,这些图像的大小不同。 They are shown in between two lines of text: 它们显示在两行文本之间:

text1.1                text1.2
ImageView(IMAGE1)      ImageView(IMAGE2)
text2.1                text2.2

text3.1
ImageView(IMAGE3)
text4.1

etc.... 等等....

If IMAGE1 is the same height as IMAGE2, everything is fine, but if IMAGE1 is longer than IMAGE2, text2.1 will run into text3.1 (padding doesn't seem to help much, as there's too much of it when images are of the same height). 如果IMAGE1是相同的高度IMAGE2,一切都很好,但如果IMAGE1比IMAGE2 ,text2.1会碰上text3.1(填充似乎没有多大帮助,因为有太多的它,当图像的同样的高度)。

I know there's a way to stretch the images in the ImageView so they are the same height, but is it possible to keep images as is and set the row height somehow? 我知道有一种方法可以在ImageView中拉伸图像,因此它们的高度相同,但是可以按原样保留图像并以某种方式设置行高吗?

You are in control over your row heights, by virtue of what you put in them. 根据你放入它们的内容,你可以控制你的行高。 Since your cells appear to have more than one widget, they are presumably wrapped in a LinearLayout or something. 由于您的单元格似乎有多个窗口小部件,因此它们可能包含在LinearLayout或其他内容中。 Set your LinearLayouts to be some specific height, and the rows will all be that height. LinearLayouts设置为某个特定高度,行将全部为该高度。

Personally, I think you should be resizing your images if you are going to have text above and below each image on a per-cell basis. 就个人而言,如果您要在每个单元格的基础上在每个图像的上方和下方放置文本,我认为您应该调整图像大小。

Use drawable as background on Layout that is your grid cell and define that drawable with: 在作为网格单元格的布局上使用drawable作为背景,并使用以下内容定义可绘制的:

<size android:height="<some height>" />

For example: 例如:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
<solid android:color="#ffffff"/>
<size android:height="60dip" />
</shape>

Here is an alternative solution that pre-measures items and sets the height of each cell to the max height in that row. 这是一种替代解决方案,用于预先测量项目并将每个单元格的高度设置为该行中的最大高度。

GridView rows overlapping: how to make row height fit the tallest item? GridView行重叠:如何使行高适合最高的项目?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM