在GridView中创建可拉伸的ImageView

5

我的GridView中的图片没有被拉伸。

我该如何拉伸它?

这是我的图片。

enter image description here

这是我想要的效果。

enter image description here

GridView

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/layout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_base"
            android:orientation="vertical" >

            <com.camitss.mcolle.ScrollableGridView
                android:id="@+id/grid_all"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="110dp"
                android:gravity="center"
                android:horizontalSpacing="10dp"
                android:numColumns="auto_fit"
                android:padding="5dp"
                android:verticalSpacing="10dp" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

网格视图项

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card_base"
android:orientation="vertical" >

<!-- Green Image -->
<ImageView
    android:id="@+id/category_card"
    android:layout_width="105dp"
    android:layout_height="105dp"
    android:layout_centerInParent="true" />

<!-- Picture -->
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:layout_centerInParent="true" />


将图像的长度和高度设置为填充父元素,而不是使用“xxdp”。 - swiftBoy
它不能工作。我已经测试过了。:D - kongkea
让我试试吧!只需分享源图像。 - swiftBoy
@RDC 你需要我的源图像吗? - kongkea
让我们在聊天中继续这个讨论 - swiftBoy
显示剩余2条评论
1个回答

6

试试这个

<!-- Picture -->

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:layout_centerInParent="true"
        android:scaleType="fitXY"
        android:adjustViewBounds="true" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接