我在布局上有两个按钮,而在大屏幕设备(平板电脑)上我想限制它们的宽度,所以它们看起来不可笑。我期望使用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