昨天我开始学习安卓编程。现在我想创建一个简单的布局。这是一张图片:
如何为按钮设置 100% 的宽度?当我写
android:layout_width="0dp"
按钮将不再显示。我的错误是什么?
这里又是代码。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
最佳答案
将按钮
的layout_width
属性设置为match_parent
:
android:layout_width="match_parent"
PS: fill_parent
和 match_parent
是一样的,但是 fill_parent
常量从 API 级别 8,现在被 match_parent
取代。
(两个常量最终都解析为-1
)
关于java - Android 按钮方向垂直宽度 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34565727/