2016-10-10 68 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); 

然後第一佈局/視圖將佔據整個父空間。

注意:至少有一個佈局/視圖應該有靜態高度(在這種情況下)。

我希望它能幫助你。

一切順利。