2015-03-02 13 views
5

我想有上顯示的其中一個RecyclerView是頂部裝載的圖標,然後消失一旦數據被加載完成設置進度條和數據後刪除加載

它看起來像:

enter image description here

誰能幫助我嗎?

我的代碼顯示了RecyclerView上方的TextView,它顯示「Loading ...」並在數據加載後消失,但RecyclerView仍然可見。

我的XML:

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/loaderTV" 
    android:text="Loading..." 
    android:layout_above="@+id/eventListRV"/> 

<android.support.v7.widget.RecyclerView 
    android:scrollbars="vertical" 
    android:id="@+id/eventListRV" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/spinner"> 



    </android.support.v7.widget.RecyclerView> 

然後在我的代碼

client.listCreators(request, new Callback<ServiceResponse<Event>>() { 
      @Override 
      public void success(ServiceResponse<Event> eventServiceResponse, Response response) { 
       eventList.addAll(eventServiceResponse.data.results); 
       Log.i("tag", String.valueOf(eventServiceResponse.data.total)); 

       if (eventList.size() > 60) { 
        adapter.notifyDataSetChanged(); 
        loadingText.setVisibility(View.GONE); 
       } 
      } 

但我想RecyclerView的數據加載時是不可見的,我想在進度條ontop的的RecyclerView其中是,我不希望它成爲一個文本視圖

回答

13
  1. 包裝你的RecyclerView和你的加載佈局(或TextView)ins ide一個FrameLayout。設置寬度和高度均爲match_parent
  2. 隱藏在OnCreate(),您的活動或您的片段onCreateView()的RecyclerView:recyclerView.setVisibility(View.GONE);
  3. 在你的回調方法隱藏加載佈局setVisibility(View.GONE),顯示您的RecyclerView與setVisibility(View.VISIBLE)和觸發適配器具有加載adapter.notifyDataSetChanged()
+0

工作,除了進度條不居中 – 2015-03-02 21:49:03

+0

好吧它的中心現在,除了加載圖標是巨大的!我想我可以找出一種方法來使它更小 – 2015-03-02 21:51:30

+0

當我使用notifyDataSetChanged'''用戶界面凍結,並且'''progressBar''停止:http://stackoverflow.com/questions/ 41945734/recyclerview與 - 100項加載太緩慢 – JCarlos 2017-01-31 03:39:43

0

爲中心的進度欄

android:layout_centerVertical="true" 
android:layout_centerHorizontal="true" 
0

的用戶對於scalling可以使用的scaleX和scaleY和調整值進度條大小爲更小的尺寸。

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/frameLayout"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:scrollbars="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <ProgressBar 
     android:id="@+id/progressBar" 
     android:visibility="visible" 
     android:scaleX="0.10" 
     android:scaleY="0.10" 
     android:textColor="@color/colorAccent" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_gravity="center"/> 
</FrameLayout>