原来说错了:右边两个按钮并排靠右,左边一个按钮填满其他空间,有代码和图片

javamy020 2013-10-17 01:12:29


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<Button
android:id="@+id/buttonLeft"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="buttonLeft" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/button3"
android:text="Button2" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button3" />

</RelativeLayout>



我要的是左边的按钮只是占用当前行的剩余空间
要怎么写呢?

...全文
198 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_mean 2013-10-17
  • 打赏
  • 举报
回复
引用 楼主 javamy020 的回复:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

   <Button
        android:id="@+id/buttonLeft"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="buttonLeft" />
   
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/button3"
        android:text="Button2" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Button3" />

</RelativeLayout>
我要的是左边的按钮只是占用当前行的剩余空间 要怎么写呢? 簇

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
 
   <Button
        android:id="@+id/buttonLeft"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        <!--只需要加这一行就可以实现-->
        android:layout_toLeftOf="@+id/button2"
        android:text="buttonLeft" />
    
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/button3"
        android:text="Button2" />
 
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Button3" />
 
</RelativeLayout>

Birds2018 2013-10-17
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginLeft="1dp"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn1" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn2" />
</LinearLayout>

<Button
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/right"
android:text="godbtn"
/>
</RelativeLayout>

tantahe 2013-10-17
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
android:id="@+id/buttonLeft"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="buttonLeft" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />

</LinearLayout>

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧