2015-03-02 121 views
1

我有一個Android應用程序,其中有一個佈局。在這個佈局中,兩個文本視圖是在這些文本視圖之間的一個視圖(視圖是一行)。自動佔用空間

動態文本插入文本視圖。 我想要這條線自動佔據剩餘的寬度。

我可以通過使用線性佈局並給每個視圖賦予權重,但在這種情況下,寬度將以某種比例固定。

我如何使這成爲可能。

<?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" 
android:background="#ffffff" > 
<TextView 
    android:id="@+id/tViewMassageOnLeft" 
    android:layout_width="wrap_content" 
    android:layout_height="25dp" 
    android:layout_toRightOf="@id/tViewArrawTowardsLeft" 
    android:gravity="center" 
    android:text="RESPONSE" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="#000000" /> 

<View 
    android:id="@+id/view1" 
    android:layout_width="100dp" 
    android:layout_height="25dp" 
    android:layout_toRightOf="@id/tViewMassageOnLeft" 
    android:background="#456765" /> 

<TextView 
    android:id="@+id/tViewMassageOnRight" 
    android:layout_width="wrap_content" 
    android:layout_height="25dp" 
    android:layout_alignParentRight="true" 
    android:gravity="center" 
    android:text="REQUEST" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="#000000" /> 
</RelativeLayout> 
+0

擁有的LinearLayout的組合包括上述3次 – VVB 2015-03-02 09:11:27

+0

如果你是把水平再設置'機器人的所有組件:layout_width =「WRAP_CONTENT」'它會調整它自動 – Apurva 2015-03-02 09:13:40

回答

1

試試這個

<?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" 
       android:background="#ffffff" > 
    <TextView 
     android:id="@+id/tViewMassageOnLeft" 
     android:layout_width="wrap_content" 
     android:layout_height="25dp" 
     android:gravity="center" 
     android:text="RESPONSE" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#000000" /> 

    <View 
     android:id="@+id/view1" 
     android:layout_width="match_parent" 
     android:layout_height="25dp" 
     android:layout_toRightOf="@id/tViewMassageOnLeft" 
     android:layout_toLeftOf="@+id/tViewMassageOnRight" 
     android:background="#456765" /> 

    <TextView 
     android:id="@+id/tViewMassageOnRight" 
     android:layout_width="wrap_content" 
     android:layout_height="25dp" 
     android:layout_alignParentRight="true" 
     android:gravity="center" 
     android:text="REQUEST" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#000000" /> 
</RelativeLayout> 

這將是結果。

image

+0

謝謝哥哥... – 2015-03-02 09:19:52