2016-07-12 99 views
1

我有這樣的佈局基礎挖掘setOnRefreshListener甚至被稱爲:安卓:如果我在我的ListView外

<RelativeLayout 
    android:id="@+id/list_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <FrameLayout 
      android:id="@+id/list_content" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"    
      android:background="@color/background" /> 

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

</RelativeLayout> 

在這個片段創作,我添加了一個具體名單:

<ListView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" 
    android:divider="@color/list_divider" 
    android:dividerHeight="1px" /> 

所以當我在紅色區域(列表視圖外)挖掘,聽者被稱爲:

mSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
    @Override 
    public void onRefresh() { 
     ... 
    } 
}); 

enter image description here

那麼,爲什麼這個監聽者被調用,我可以避免這種行爲?

+0

變化'機器人:layout_height = 「WRAP_CONTENT」''到機器人:layout_height = 「match_parent」'或SwipeRefreshLayout使用'爲高度 –

+0

SwipeRefresh設定wrap_content'到matchcontent,使得紅色區域是它 – user6547359

+0

'機器人部分:layout_height =「wrap_content」' –

回答

0
<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipe_list_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ListView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/white" 
android:divider="@color/list_divider" 
android:dividerHeight="1px" /> 

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

<RelativeLayout 
    android:id="@+id/list_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <FrameLayout 
      android:id="@+id/list_content" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"    
      android:background="@color/background" /> 

</RelativeLayout> 

使用本 您是刷卡實現對刷新整個片段,包括ListView控件。

+0

我不明白你的帖子? – anthony