通常のボタンとImageButtonを同じlayout_weight
に設定しようとすると、LinearLayoutで奇妙な動作が発生します。画像ボタンのandroid:src
リソースは非常に小さく、問題なくImageButtonの内部に収まります。幅が同じであるにもかかわらず、ImageButtonの幅は何らかの理由で通常のボタンの残りのサイズの約2/3です。 ImageButtonのlayout_weight
に10を掛ければ、それは正しいサイズに近いが、なぜこれは機能しないのだろうか?Android ImageButtonとButtonのlayout_weightの幅が異なるのはなぜですか?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/clear"/>
<Button
android:id="@+id/left_paren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/left_paren"/>
<Button
android:id="@+id/right_paren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/right_paren"/>
<ImageButton
android:id="@+id/backspace"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:contentDescription="@string/backspace"
android:src="@drawable/backspace"/>
</LinearLayout>
いつも使うと思います。あなたのアンドロイドのlayout_width = "0dp" .instead:layout_width = "wrap_content"。layout_weightを使うたびに。 –
http://stackoverflow.com/a/41451132/2219600 – amalBit