【发布时间】: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