2011-02-10 17 views
1

我有一個具有LinearLayout作爲包含TextViews的子項的RelativeLayout。RelativeLayout:不能使用帶有鏈接到LinearLayout子項的layout_below?

我想將ImageViews放置在layout_alignRight =「@ id/userdetail_tv_special」的TextViews的右側,但不知何故,這是行不通的。

無法將RelativeLayout的子元素「鏈接」到LinearLayout的子元素嗎?任何想法如何我可以實現這一點,而無需爲每個按鈕創建另一個RelativeLayout?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
    <LinearLayout 
     android:id="@+id/userdetail_lin_btncontainer" 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:layout_below="@id/userdetail_lin_divider" 
     android:padding="6dp" > 
     <TextView 
      android:id="@+id/userdetail_tv_special" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Special" 
      android:background="#cccccc" /> 
     <!-- here are more TextViews like this one --> 
    </LinearLayout> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@id/userdetail_tv_special" 
     android:src="@drawable/ic_detail_special" /> 
     <!-- much more views and stuff --> 
</RelativeLayout> 

回答

3

這似乎是合乎邏輯的,我認爲你不能指向「layour」更深層次的:你可以佈局對每個-以外的RelativeLayout的孩子,但你的LinearLayout是,你可以作爲一個使用的完整視圖參考。

如果您希望能夠定位相對於textview的視圖,請將它們放置爲相關佈局的直接子對象。順便提一下,我不明白爲什麼你需要一個LinearLayout。

+1

的LinearLayout中有5個TextViews與layout_width = FILL_PARENT和layout_weigth = 1〜STRETCH時他們填寫屏幕的整個寬度...有另一種可能做到這一點? – qedejavu 2011-02-10 14:50:16

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imgview" 
    android:src="@drawable/ic_detail_special" /> 

<LinearLayout 
    android:id="@+id/userdetail_lin_btncontainer" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:layout_below="@id/userdetail_lin_divider" 
    android:layout_alignLeft="@id/imgview" 
    android:padding="6dp" > 
    <TextView 
     android:id="@+id/userdetail_tv_special" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Special" 
     android:background="#cccccc" /> 
    <!-- here are more TextViews like this one --> 
</LinearLayout> 

     <!-- much more views and stuff --> 

相關問題