2016-11-22 85 views
0

我在列表視圖的底部有一個帶有listview和兩個按鈕並排的佈局。一切工作正常,直到我爲我的列表視圖添加swiperefreshlayout。添加swiperefreshlayout後不見了按鈕

我的代碼如下。

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="#FFF" 
> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:id="@+id/search_bar" 
    android:background="@color/colorPrimaryDark" 
    android:orientation="vertical" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    > 

    <EditText 
     android:id="@+id/keyword_editText" 
     android:layout_width="fill_parent" 
     android:layout_height="30dp" 
     android:background="@drawable/search_edit_text" 
     android:hint="Keyword" 
     android:textColorHint="@color/list_item_title" 
     android:textColor="#000" 
     android:layout_centerVertical="true" 
     android:maxLines="1"/> 


</RelativeLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/listView_layout" 
    android:orientation="vertical" 
    android:layout_below="@+id/search_bar" 

    > 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/refresh" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 

    <ListView 
     android:layout_width="wrap_content" 
     android:layout_height="0dip" 
     android:layout_weight="1" 
     android:id="@+id/RsListView" 
     android:dividerHeight="1dp" 
     android:divider="#D3D3D3"/> 

    </android.support.v4.widget.SwipeRefreshLayout> 

    <LinearLayout 
     android:id="@+id/test" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <Button 
      android:id="@+id/req_history_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Request History" 
      android:layout_weight="1" 
      android:background="@drawable/request_history_button" 
      android:textColor="@drawable/button_text_color" 
      /> 
     <Button 
      android:id="@+id/apprv_history_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Approval History" 
      android:layout_weight="1" 
      android:background="@drawable/approval_history_button" 
      android:textColor="@drawable/button_text_color" 
      /> 
    </LinearLayout> 

</LinearLayout> 

對不起,這裏傾倒我的代碼,因爲我無法弄清楚爲你們理解我的代碼的任何其他方式。

請幫

回答

1

裏面LinearLayout通常都是孩子根據方位甚至已經維度。但是,如果您希望某個孩子佔用一小部分地方,而另一個孩子則可以填充其餘部分,則可能對layout_weight參數感興趣。如果填充該空間的孩子獲得android:layout_weight="1",則它將填充空間,爲其他視圖提供空間。

爲了看到按鈕添加android:layout_weight="1"SwipeRefreshLayout和設置android:layout_height="0dp"。這將使您的按鈕可見。

+0

hi @R。 Zagórski,因爲我有我的按鈕linearlayout之前我的swiperefreshlayout爲什麼我應該爲我的swiperefreshlayout添加重量=「1」?我的按鈕顯示不會更糟嗎? –

+1

現在,您的SwipeRefreshLayout的高度是match_parent,所以它將佔據整個LinearLayout並隱藏您的按鈕。當您向您的SwipeRefreshLayout添加layout_weight = 1時,意味着它應占用您的LinearLayout中剩餘的任何空閒空間。所以按鈕將首先放置,並且它們將獲得所需的所有空間,因爲它們具有wrap_content的高度,然後所有剩餘的空間將由SwipeRefreshLayout獲取。 – rhari

+0

@rhari把它的weight =「1」和height =「match_parent」thx –