好的,所以我需要一个按钮来始终占据线性布局的 25%,无论其中有什么。其他 75% 将是 TextView 字段。 这是我目前所拥有的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="0dp "
android:layout_weight=".25"
android:text="" />
<EditText
android:id="@+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".75"
android:hint="@string/edit_message" />
</LinearLayout>
但是,在 0dp 时按钮消失了,在 wrap_content 时它总是选择文本来设置宽度。我如何强制它使用权重作为设置宽度的方法。
最佳答案
试试这个....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<EditText
android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="@string/edit_message" />
</LinearLayout>
关于android - 使按钮占线性布局的 25%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19075217/