レイアウトには2つのボタンがあり、大画面のデバイス(タブレット)では、その幅をキャップしてばかげて見えないようにしたいと思います。私はmaxWidth属性を使用することを期待していましたが、明らかに私のシナリオでは何もしません。レイアウト定義は次のとおりです。ボタンはレイアウトの全幅を使い、maxWidthの値は無視します。なぜボタンのmaxWidthが機能しないのですか?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxWidth="100dp"
android:text="Button 1"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxWidth="100dp"
android:text="Button 2"
/>
</LinearLayout>
なぜ、この(明らかにクレイジーな)制限を回避する方法は?
ボタンlayout_widthが0dpでwrap_contentでないのはなぜですか? – antlersoft
@antlersoft - 0dpの幅とlayout_weightの組み合わせが、兄弟要素の幅と一致すると、幅が同じであることが保証されます – ataulm