2016-10-10 67 views

回答

0

是的。有可能的。

让我们考虑下面的XML,

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

    //First View or layout 
    <RelativeLayout    
     android:id="@+id/first_layout" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:background="#000"> 
    </RelativeLayout> 

    //Second View or layout 
    <RelativeLayout    
     android:id="@+id/second_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/first_layout" 
     android:background="#8b3737"> 
    </RelativeLayout> 

</RelativeLayout> 

在你的活动,

RelativeLayout layout_one=(RelativeLayout)findViewById(R.id.first_layout); 
RelativeLayout layout_two=(RelativeLayout)findViewById(R.id.second_layout); 

当你设置,

layout_one.setVisibility(View.GONE); 

那么第二个布局/视图会占据整个父空间。

注:我采取了相对布局的例子。它可以是任何视图。但父母应该是一个RelativeLayout。

如果你想第二个布局被隐藏和第一个布局应填写父母,

那么XML会,

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

    //First View or layout 
    <RelativeLayout    
     android:id="@+id/first_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/second_layout" 
     android:background="#000"> 
    </RelativeLayout> 

    //Second View or layout 
    <RelativeLayout    
     android:id="@+id/second_layout" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:background="#8b3737"> 
    </RelativeLayout> 

</RelativeLayout> 

当你设置,

layout_two.setVisibility(View.GONE); 

然后第一布局/视图将占据整个父空间。

注意:至少有一个布局/视图应该有静态高度(在这种情况下)。

我希望它能帮助你。

一切顺利。