android - 一个按钮在左侧另一个在右侧

标签 android xml button

我知道有这样的问题,但大多数时候他们的问题似乎是他们没有将布局对齐为填充父级。好吧,我这样做了,所以我不确定为什么我的按钮仍然无法执行。可能是因为我使用的所有布局?

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/face">

  <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:gravity="center">
  <ImageView android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:id="@+id/eyes" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/eyes1" />
        <LinearLayout android:layout_marginTop="50dp"  android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
            <Button android:id="@+id/eyesback" android:layout_width="50dp" android:layout_height="50dp" />
            <Button android:id="@+id/eyesforward" android:layout_height="50dp" android:layout_width="50dp" android:layout_gravity="right"></Button>
        </LinearLayout>
  </RelativeLayout>

</LinearLayout>

它可能很简单,我也错过了。感谢您的帮助。

最佳答案

试试这个

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/face">

  <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:gravity="center">
  <ImageView android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:id="@+id/eyes" android:background="@drawable/eyes1" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
        <RelativeLayout android:layout_marginTop="50dp"  android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
            <Button android:id="@+id/eyesback" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true"/>
            <Button android:id="@+id/eyesforward" android:layout_height="50dp" android:layout_width="50dp" android:layout_gravity="right" android:layout_alignParentRight="true"></Button>
        </RelativeLayout>
  </RelativeLayout>

</LinearLayout>

我只是将 LinearLayout 更改为 Relative 布局并将属性设置为一个按钮以从左到右下车。

关于android - 一个按钮在左侧另一个在右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7466331/

相关文章:

android - 第二次尝试使用 ParseFacebookUtils 登录 Facebook 时,Facebook 访问 token 为空

android - 应用程序 :transformClassesWithDexForDebug exception and java. util.concurrent.ExecutionException

java - Google Play 应用内评论 API java.lang.ClassCastException

sql-server - SQL Server - 使用 UTF-8 编码定义 XML 类型的列

javascript - 在 Odoo ERP 系统上创建自定义字段小部件

php - 从另一个域获取 XML 文件到 Mysql 数据库

javascript - 使用 Twitter Bootstrap 触发 Nav-Tab 的按钮

android - Xposed 和 onCheckedChanged 代码 - 编译错误

android - 如何使RealtiveLayout中的ToggleButton和ImageButton高度相同?

html - 在悬停时将按钮的宽度增加几个百分点