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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置