【问题标题】:GridView imageviews are croppedGridView 图像视图被裁剪
【发布时间】:2015-02-20 09:35:34
【问题描述】:

我的 android 应用程序中有一个 GridView,每个单元格中有两个图像视图。问题是我必须将其中一个图像视图的重力设置为中心,当我这样做时,图像视图会被裁剪。我想问是否有办法保持图像的纵横比并防止它被裁剪。
PS:如果我不使用重心,我可以通过使用 scaletype center 来实现这一点,但在我的应用程序中,我需要将图像居中,所以我需要使用重心。
非常感谢
这是布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/bgcolor"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">

    <FrameLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
         >
        <ImageView
            android:id="@+id/imageView1"
            android:paddingTop="60dp"
            android:layout_marginTop="15dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/shelf_center" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:scaleType="fitCenter"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp" />


    </FrameLayout>

</RelativeLayout>

【问题讨论】:

    标签: android gridview imageview scaletype


    【解决方案1】:

    试试android:scaleType="fitCenter"android:gravity="center" 会成功的。

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:scaleType="fitCenter" >
    </ImageView>
    

    【讨论】:

    • 谢谢,但对作物没有任何影响。
    • 你能分享一下你的网格截图吗
    【解决方案2】:

    你试试

    android:scaleType="centerInside"
    

    android:scaleType="fitXY"
    

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 1970-01-01
      • 2016-05-04
      • 2014-07-29
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      相关资源
      最近更新 更多