GridView的高度太高内使用ImageView的时 [英] gridView height is too tall when using an imageView inside

查看:185
本文介绍了GridView的高度太高内使用ImageView的时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,高度为GridView里面的细胞。我的每一个细胞都会有一个ImageView的内部,像这样:

I'm having an issue with the height for the cells inside the GridView. Each of my cells will have an imageView inside like so:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">

<GridView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:id="@+id/eventGridView" android:numColumns="2"/>
</LinearLayout>

下面是ImageView的每个细胞

Here is the ImageView for each cell

<com.example.scheduling_android.view.RoundedCornerImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:maxWidth="150dp"
        android:maxHeight="150dp"
        xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/eventImageView"
        android:adjustViewBounds="false"/>

我在玩弄不同的图像大小为我的ImageView的。我得到的是,每当我的图像变大(例如,400×400像素)的单元的高度变得很高(绕宽度的两倍大小,请注意,我设置网格使用2列)。但是,当我将图像保存为一个更小的尺寸(例如,160×160px),在GridView就出来了正常。的高度和宽度的匹配

I was playing around with different image size for my imageView. What I got was that whenever my image becomes larger (say, 400 x 400px) the height of the cell becomes very tall (around double the size of the width, note that I set the grid to use 2 columns). However, when I save my image as a smaller size (say, 160 x 160px), the gridView came out correctly. The height and the width matches.

下面是截图:

似乎什么问题吗?会不会是大的图像导致GridView控件来计算其单元格的高度不正确?我能做些什么来解决这个问题?

What seems to be the problem? Could it be that the large image is causing gridView to calculate the height of its cell incorrectly? What can I do to fix this?

推荐答案

我觉得你没有设置adjustViewBounds为true。你可以设置如下?

I think you haven't set adjustViewBounds to true. Can you set as follows?

imageView.setAdjustViewBounds(true);

这篇关于GridView的高度太高内使用ImageView的时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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