使用这些图像:
(333x300)
(1680x1050)
这个布局:
<?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="wrap_content"
android:layout_margin="12dp"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/apple" />
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/apple" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<ImageButton
style="@style/OtherButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/orange" />
<ImageButton
style="@style/OtherButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/orange" />
</LinearLayout>
</LinearLayout>
给出这个结果:
只有单嵌套布局,苹果和橙色按钮的大小相同。在使用 Eclipse 之后,我注意到按钮在图像较大时往往会更高,但相对比例似乎并没有遵循特定的模式。
为什么按钮有不同的高度?我可以使用另一种方法来缩放屏幕分辨率和密度吗?