2015-08-16 40 views
1

任何人都可以幫助我嗎?無法在listView中上傳,因爲SwipeRefreshLayout

我在一個RelativeLayout中有一個ListView,它是SwipeRefreshLayout的子節點。這是一個片段的視圖。

這裏是一張圖片的佈局,這個截圖是在我處於ListView底部的時候拍攝的,所以當我嘗試上去的時候,我還加載了SwipeRefresh,而且很難去到ListView的頂部。

我曾嘗試類似於在RelativeLayout之前和SwipeRefreshLayout之後包含ScrollView併成功。滾動工作良好,但它只能工作,如果我擴展listView到2400 DP和我沒有得到好的看法。我有一些空的ListView的底部,這不是我想要的。

因此,如果任何人有任何建議,我可以做什麼,讓我知道。

下面是XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<!-- This is the fragment to be displayed for a section associated with a tab --> 
<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipe_refresh_layout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/layout_round_rect_shape" > 

     <ListView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:divider="@color/list_divider" 
      android:dividerHeight="1dp" 
      android:listSelector="@drawable/lista_preporuka_selector" >   
     </ListView> 

    </RelativeLayout> 

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

enter image description here

回答

1

就直接把列表視圖輕掃TOR刷新內部並取出realtive佈局 這個偉大的工程給我

0

刷卡刷新不是設計比它的內部列表中的其他任何東西。 如果您必須以這種方式禁用刷新,直到您的列表達到頂部,但我不確定這是否可行。

+0

我可以確認,你的建議的工作。每當我被迫有一個不是'SwipeRefreshLayout'的直接子類的'ListView'時,我採取了同樣的方法。 –

0

我解決了這個編程使用該解決方案解釋here

基本上你重寫滾動偵聽器列表視圖,只允許刷卡刷新如果滾動在列表的頂部:

listView.setOnScrollListener(new AbsListView.OnScrollListener() { 
    @Override 
    public void onScrollStateChanged(AbsListView view, int scrollState) { 

    } 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 

    int topRowVerticalPosition = (listView== null || listView.getChildCount() == 0) ? 0 : listView.getChildAt(0).getTop(); 
    swipeContainer.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0); 

    } 
});