2015-09-15 53 views
0

我有一個視圖設置爲大多數時間(視圖A)和其後的視圖始終可見(視圖b),在某些情況下,View A視圖設置爲可見狀態,當發生這種情況時,View B將不可見(主要是因爲View A在出現時阻止了它)。我想知道是否有一種方法讓系統在出現時將視圖B重新定位到視圖A下方。Android將另一個視圖的可見性從已更改爲可見時向下滑動一個視圖

<RelativeLayout 
    android:id="@+id/require_info" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
     android:id="@+id/payment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:visibility="gone"> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="0.2dp" 
      android:layout_marginTop="10dp" 
      android:background="#c0c0c0" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      android:text="@string/quantity_label" 
      android:textSize="10sp" 
      android:textStyle="bold" /> 
</LinearLayout> 
<LinearLayout 
     android:id="@+id/contact_info" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/payment" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/contact_label" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Contact Information" 
      android:textColor="#90CAF9" 
      android:textSize="15sp" /> 
</LinearLayout> 
</RelativeLayout> 

回答

0

如果你有View ALinearLayoutView B以上,如果同時設置A和B可見,與重繪佈局,你會看到上面View AView B。確保您的LinearLayoutverticalorientation

0

實際上,您需要將第一個LinearLayout的高度更改爲「wrap_content」,它目前設置爲「match_parent」。因此,如果您使視圖A可見,它將獲得屏幕上的整個可用空間,並且您的視圖B永遠不會顯示。

0

線性佈局適合您的設計。以下示例顯示瞭如何做到這一點。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout" 
     android:orientation="vertical" 
     android:visibility="visible" 
     android:layout_weight="0.5" 
     > 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button1" 
      android:id="@+id/button" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout2" 
     android:visibility="visible" 
     android:layout_weight="0.5" 
     > 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button2" 
      android:id="@+id/button2" /> 
    </LinearLayout> 
</LinearLayout> 

在上面,當您試圖使人們看到第一線佈局和隱藏第二線性佈局的佈局,可見將採取全屏幕,反之亦然。如果將兩個佈局設置爲可見,則佈局可以正確顯示(第一個佈局及其下方的第二個佈局)。

相關問題