Android按钮布局 – 在整个屏幕上并排显示两个按钮

前端之家收集整理的这篇文章主要介绍了Android按钮布局 – 在整个屏幕上并排显示两个按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个按钮,我希望水平并排显示,但它们一起填充手机的水平长度.高度是包裹内容,这很好.我现在的问题是只显示一个按钮(在屏幕上伸展).

这是我的XML代码

  1. <LinearLayout
  2. android:id="@+id/page_buttons"
  3. android:orientation="horizontal"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:gravity="center_horizontal"
  7.  
  8. >
  9. <Button
  10. android:id="@+id/prevButton"
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:text="PrevIoUs"
  14. />
  15.  
  16. <Button
  17. android:id="@+id/nextButton"
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content"
  20. android:text="Next"
  21. />

解决方法

更改按钮XML以包含layout_weight属性
  1. <Button android:id="@+id/nextButton"
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. android:layout_weight="1"
  5. android:text="Next"/>

猜你在找的Android相关文章