2
這可能是一個簡單的佈局問題,但我可以得到我想要的。Android:簡單佈局問題
我有一個LinearLayout(這是水平的),我想顯示裏面的2個佈局,一個在左邊,一個在右邊(它們本身有覆蓋,按鈕等等)。我希望正確的一個始終顯示完整,並且只有在右側完全顯示後才顯示左側,如果空間允許的話。
UPDATE
<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%,剩下的剩餘部分將用於左側。我該怎麼做?
非常感謝!
OK,我承認我只是在這裏挑剔,我知道'0dp'在功能一樣' 0px',但我寧願將'dp'看作佈局文件中的單元而不是'px'。 ;) – Squonk
謝謝!有些東西還在破碎。如果我在左邊(第一個)relativeLayout上的元素上放置0px的寬度,那麼只顯示右邊。如果我放一個wrap_content的寬度,那麼左邊的文本顯示出來,但是不顯示正確的RelativeLayout。 – user1777907
@Squonk我其實是相反的 - 我把'px'放在那裏,所以我知道*它的意思是0.如果我把'0dp',我會說「...這不應該是零。 「個人喜好! ;) – Eric