【发布时间】:2013-08-22 11:55:27
【问题描述】:
我是 Android 新手。我在一个活动中有多个图像视图,并且会添加更多。我将这些图像视图用作按钮。我遇到的问题是让它们都正确适配并根据屏幕尺寸进行缩放。我可以得到一些帮助吗?
这是 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/homeBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="@drawable/homebackground" />
<ImageView
android:id="@+id/publicAffairs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/publicaffairs" />
<ImageView
android:id="@+id/actionAlerts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="1dp"
android:layout_toRightOf="@+id/publicAffairs"
android:src="@drawable/actionalerts" />
</RelativeLayout>
我用作按钮的两个图像视图不会根据设备大小进行缩放。
【问题讨论】:
-
你能链接到你想要达到的目标的图片吗?
-
@user2029585 你看到我的回答了吗?
-
你想要每行两个等间距的按钮吗?
-
是的,我确实希望它们均匀分布。
-
我的意思是,看起来第一行应该有第三张图像,而您最多可以有三行。如果图像完全不失真很重要,我认为您不能仅使用 XML 来做到这一点。