2013-03-14 109 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

相关问题