【问题标题】:How to view images in GridView with its original dimensions如何在 GridView 中查看原始尺寸的图像
【发布时间】:2012-09-09 03:34:02
【问题描述】:

我想在 GridView 中显示一组图像(它们具有相同的尺寸)。 在 GirdView 和 GirdView Item 的布局下方.. 问题是图像高度被拉伸。为什么?

GridView 布局:

<GridView
    android:id="@+id/gvRecipes"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/include1"
    android:layout_margin="0dp"
    android:background="@drawable/bg"
    android:gravity="right"
    android:horizontalSpacing="10dp"
    android:padding="0dp"
    android:verticalSpacing="5dp" >
</GridView> 

GridView 项目是:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/include21"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:background="@drawable/btn"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/imgRecibeImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"

        android:src="@drawable/img1" />

    <TextView
        android:id="@+id/txtRecibeName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_gravity="bottom"
        android:background="#80000000"
        android:gravity="right"
        android:padding="5dp"
        android:text="Crispy Chicken and Sandwich"
        android:textColor="#ffffff"
        android:textSize="17sp" />

</FrameLayout>

【问题讨论】:

  • 所以其实你可以设置imageview fix的宽高来正常查看。

标签: android xml layout gridview imageview


【解决方案1】:

在您的秤类型中,您使用了fitXY

fitXY:只有在不成比例的缩放不影响图形时才应使用此选项。对于位图图形,这几乎总是不好用。这会将源图像的宽度设置为视图的宽度,将源图像的高度设置为视图的高度,而不保持源图像的纵横比。

现在您的layoutimageview 宽度为match_parent,因此图像将以父视图的全宽显示,但高度为wrap_content,因此imageView 将调整@987654328 @你的每一张图片。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 2023-02-04
    • 2015-09-12
    相关资源
    最近更新 更多