2013-04-30 123 views
0

我有一個相對佈局(RV1),其中頂部是列表視圖。在這之下,我有另一個相對視圖(R2),它包含一個圖像和按鈕。 最後在R2下面,在R1的底部有一個編輯框和一個按鈕(B1)。當圖層可見性發生變化時刷新圖層

最初,R2被設置爲可見性(不存在),因此列表僅位於編輯框的頂部。但是,當我按下按鈕B1時,我希望R2可見並且列表現在可以在R2之上移動。

在xml設置中,列表設置爲高於R2:android:layout_above =「@ id/R2Layout」 但是由於R2最初設置爲不存在,列表位於編輯框的頂部。沒關係。

我的問題是,一旦按鈕B1被按下,R2就會變得可見,但是列表不會讓R2產生空間並移動到R2上方。 R2和列表相互重疊。

我試圖通過做view.invalidate()使整個視圖刷新自己,但它沒有工作。

我該如何解決這個問題?

下面是xml代碼。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/r1" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" > 

<EditText 
    android:id="@+id/et" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="5dp" 
    android:layout_marginLeft="5dp" 
    android:layout_toLeftOf="@+id/b1" 
    android:padding="5dp" 
    android:paddingTop="10dp" > 

</EditText> 

<RelativeLayout 
    android:id="@+id/r2" 
    android:visibility="gone" 
    android:layout_width="wrap_content" 
    android:layout_margin="5dp" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/et" 
    android:layout_alignParentLeft="true" > 

    <ImageView 
     android:id="@+id/iv" 
     android:visibility="gone" 
     android:layout_width="80dp" 
     android:layout_height="80dp" /> 

    <Button 
     android:id="@+id/b2" 
     android:visibility="gone" 
     android:layout_marginLeft="5dp" 
     android:layout_toRightOf="@+id/iv" 
     android:layout_alignTop="@+id/iv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="button" /> 
</RelativeLayout> 

<FrameLayout 
    android:id="@+id/frameLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@id/r2" 
    android:layout_marginBottom="10dp" > 
    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:dividerHeight="2.0sp" 
     android:fastScrollEnabled="true" 
     android:smoothScrollbar="true" 
     android:stackFromBottom="true" /> 

    <!-- Here is the view to show if the list is empty --> 

    <LinearLayout 
     android:id="@+id/empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <!-- If the list is empty because there are no files... --> 

     <TextView 
      android:id="@+id/empty_text" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="center" 
      android:visibility="invisible" 
      android:text="List empty" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </LinearLayout> 
</FrameLayout> 

<Button 
    android:id="@+id/b1" 
    android:layout_width="50dip" 
    android:layout_height="50dip" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginRight="5dp" /> 

</RelativeLayout> 
+1

你應該張貼的XML進行你的佈局。 – dymmeh 2013-04-30 03:54:21

+0

在這種情況下,您的佈局通常存在問題。如果其他人可以看到他們可以幫助你的佈局。 – HalR 2013-04-30 03:55:39

+0

我已經建議用xml更新。謝謝 – fawx 2013-04-30 04:17:16

回答

0

您可以將父佈局更改爲LinearLayout並且可以包裝你ButtonEditTextHorizontal Linear Layout

你的最終代碼會是這個樣子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/r1" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/r2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:visibility="gone" > 

     <ImageView 
      android:id="@+id/iv" 
      android:layout_width="80dp" 
      android:layout_height="80dp" 
      android:visibility="gone" /> 

     <Button 
      android:id="@+id/b2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignTop="@+id/iv" 
      android:layout_marginLeft="5dp" 
      android:layout_toRightOf="@+id/iv" 
      android:text="button" 
      android:visibility="gone" /> 
    </RelativeLayout> 

    <FrameLayout 
     android:id="@+id/frameLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_weight="1" > 

     <ListView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:dividerHeight="2.0sp" 
      android:fastScrollEnabled="true" 
      android:smoothScrollbar="true" 
      android:stackFromBottom="true" /> 

     <!-- Here is the view to show if the list is empty --> 

     <LinearLayout 
      android:id="@+id/empty" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

      <!-- If the list is empty because there are no files... --> 

      <TextView 
       android:id="@+id/empty_text" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center" 
       android:text="List empty" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:visibility="invisible" /> 
     </LinearLayout> 
    </FrameLayout> 

    <LinearLayout 
     android:id="@+id/" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <EditText 
      android:id="@+id/et" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:ems="10" 
      android:padding="5dp" 
      android:paddingTop="10dp" > 

      <requestFocus /> 
     </EditText> 

     <Button 
      android:id="@+id/b1" 
      android:layout_width="match_parent" 
      android:layout_height="50dip" 
      android:layout_marginRight="5dp" /> 
    </LinearLayout> 

</LinearLayout> 
相關問題