2013-03-14 106 views
1

我正在處理佈局。 temp1包含在temp2中。 temp1工作正常,但是當我將它包含在temp2中時。它填充整個屏幕,因爲temp1中的根被設置爲fill_parent。在這種情況下可能有什麼解決方案?包含佈局在另一個佈局中填充視圖

我想在temp1中心的一個小區域temp2中顯示佈局。

temp1.xml

<RelativeLayout android:layout_height="fill_parent" 
       android:layout_width="fill_parent"> 


</RelativeLayout> 

temp2.​​xml

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


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:id="@+id/relativeLayout"> 
    <include 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      layout="@layout/temp1"/> 
</RelativeLayout> 

</RelativeLayout> 

回答

1

您可以覆蓋要包括的佈局的根視圖的layout_*領域,在這種情況下,他們將覆蓋在根RelativeLayout@layout/temp1

您可以使用保證金,並調整到你想要的邊框量(100dp只是一個例子):

<include 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="100dp" 
     layout="@layout/temp1"/> 

或者你可以設置你想要的大小(100dp只是一個例子):

<include 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     layout="@layout/temp1"/> 

或者你也可以證明是有內容(temp1中有什麼截至目前):

<include 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/temp1"/> 

有關更多信息,請參閱http://developer.android.com/training/improving-layouts/reusing-layouts.html

+0

是的,我意識到這一點,事實證明這是現在唯一的解決方案。謝謝你的回答。我必須給dp做一個尺寸來做我想做的事情。 – VendettaDroid 2013-03-14 22:56:10

相關問題