znl_12 2013-05-06 08:37 采纳率: 0%
浏览 4062
已采纳

为什么一个按钮在左边,其余的按钮都在右边?

问题好像是没有把布局作为fill parent 对齐,下面是我使用的代码
为什么一个按钮在左边,其余的按钮都在右边?

<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>
  • 写回答

2条回答

  • Baby_Bonnie 2013-05-07 05:24
    关注

    使用下面的代码:

    <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>
    

    把 teh LinearLayout 改变为 Relative layout。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误