Android按钮布局 - 在整个屏幕上并排放置两个按钮

标签 android xml button android-linearlayout

我有两个按钮,我想水平并排显示,但它们一起填满了手机的水平长度。高度是包装内容,没关系。我现在的问题是只显示一个按钮(在屏幕上拉伸(stretch))。

这是我的 XML 代码:

<LinearLayout 
   android:id="@+id/page_buttons"
   android:orientation="horizontal"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:gravity="center_horizontal"

   >
   <Button
        android:id="@+id/prevButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Previous"
   /> 

   <Button
        android:id="@+id/nextButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Next"
   />

最佳答案

更改您的按钮 XML 以包含 layout_weight 属性:

<Button android:id="@+id/nextButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Next"/>

关于Android按钮布局 - 在整个屏幕上并排放置两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7248957/

相关文章:

Java GUI 按钮不会将字符串打印到界面

xml - SQLAlchemy TypeDecorator 不起作用

android - 服务器响应 xml 或 json 对象 android

android - 如何在 Android 中使用 XML 引用库中另一个包中的字符串?

java - ArrayAdapter 中带有按钮的自定义 View

ios - 我如何为 objective-c 中的按钮设置动态约束

android - 协调器布局中的按钮单击不起作用

Android 前置摄像头 API

php - 如何将时间戳转换为获取时间戳的国家/地区特定时间。

android - 推特可以上传照片吗?如果是,那么如何从 Android 发布或上传照片?