Android:简单布局问题

Android:简单布局问题,android,layout,Android,Layout,这可能是一个简单的布局问题,但我能得到我想要的 我有一个LinearLayout(水平),我想在里面显示两个布局,一个在左边,一个在右边(它们本身有重叠、按钮等)。我希望右一个总是完全显示,左一个只有在右一个完全显示后才显示,如果空间允许的话 更新 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" a

这可能是一个简单的布局问题,但我能得到我想要的

我有一个LinearLayout(水平),我想在里面显示两个布局,一个在左边,一个在右边(它们本身有重叠、按钮等)。我希望右一个总是完全显示,左一个只有在右一个完全显示后才显示,如果空间允许的话

更新

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="20dp" >

    <RelativeLayout
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:singleLine="true" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000111" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerVertical="true" />
    </RelativeLayout>
</LinearLayout>

使用此代码,仅显示左侧。如果我把第一个RelativeLayout的权重改为1,那么两者都占屏幕的50%,这就是我所期望的

我想要的是权利,如果需要100%,如果需要少于100%,剩下的就用左边的。请问我怎么做


非常感谢

从右侧移除权重,并将左侧的宽度设置为0,权重设置为1:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="20dp" >

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <!-- ..... -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <!-- ...... -->

    </RelativeLayout>
</LinearLayout>


好吧,我承认我只是在这里挑三拣四,我知道
0dp
在功能上与
0px
相同,但我更愿意将
dp
作为布局文件中的一个单元,而不是
px
)谢谢有些东西还在破裂。如果我在左侧(第一个)relativeLayout上的元素上设置宽度为0px,则仅显示右侧。如果我放置了一个宽度为wrap_的内容,那么左边的文本会显示出来,但右边的RelativeLayout不会显示。@Squonk我实际上是相反的——我将
px
放在那里,所以我知道它应该是0。如果我把
0dp
,我会说“……这不应该是零。”个人偏好!;)@用户1777907问一个愚蠢的问题:你确定吗?确保右侧布局没有指定权重,左侧布局有。这就是向操作系统发出调整应该发生的信号。如果您仍然对这个精确的布局有问题,我可以将它放到Eclipse中并进行测试……您完全正确!右翼正在破坏它!删除它,它看起来像我打算(或非常非常接近,只是一些调整)!非常感谢你的帮助,我真的很感激,谢谢!