これらの画像の使用:
(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をいじってみたところ、画像が大きいほどボタンが高くなる傾向があることに気付きましたが、相対的な比率は特定のパターンに従っていないようです。
ボタンの高さが異なるのはなぜですか?画面の解像度と密度に合わせて拡大縮小できる別の方法はありますか?