1

我正在尝试在 a 中显示图像列表GridView,并且我只想裁剪此列表中图像的中心。下面是每个图像项的布局:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/place_image"
        android:src="@drawable/ic_res"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:scaleType="centerCrop"/>

这是包含网格视图的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout android:id="@+id/upload_view"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
                  android:background="#f6f6f6"
                  android:padding="10dp"
                  android:visibility="gone">
        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal">
            <ImageButton android:id="@+id/photo_select"
                    android:layout_width="50dp"
                    android:layout_height="40dp"
                    android:scaleType="fitXY"
                    android:src="@drawable/ic_photo"/>
            <EditText android:id="@+id/photo_caption"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:hint="@string/caption"
                      android:inputType="textMultiLine"/>
        </LinearLayout>
        <TextView  android:id="@+id/photo_path"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="" />

        <Button android:id="@+id/photo_upload"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/upload_photo"
                android:textStyle="bold"
                android:textColor="#ffffff"
                android:layout_gravity="right"/>
    </LinearLayout>
    <TextView android:id="@+id/no_photos"
              android:layout_height="wrap_content"
              android:layout_width="match_parent"
              android:gravity="center"
              android:textStyle="bold"
              android:textSize="20dp"
              android:text="@string/no_photos"
              android:visibility="gone" />
    <GridView android:id="@+id/grid_photos"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:columnWidth="120dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:gravity="center" />
</LinearLayout>

这是我得到的结果:

在此处输入图像描述

这很奇怪,因为图像都以一种奇怪的方式裁剪。以下是我的原始图片之一:

在此处输入图像描述

我从来没有遇到过这个问题,所以如果你们中的任何人熟悉这个,请帮我找出原因。谢谢!

Ps:我猜这只能是xml布局的问题所以我认为没有必要在这里包含我的android源代码。但如果确实如此,请让我知道问题可能来自哪里,我将用我的代码编辑这个问题。

4

1 回答 1

3

原因是GridView清除了为图块设置的所有布局参数,并设置了自己的布局参数,因此最好ImageViewRelativeLayout. 这与所有AdapterView类似的 ListViewGallery等都是相同的。

于 2013-03-26T14:03:04.640 回答