2016-12-16 135 views
2

我想顯示的最初加載從API獲取數據之前的骨架圖一RecyclerView的圖像。在下面的示例中,正在顯示一個簡單的圖像視圖和文本。顯示佔位符在recyclerview

<android.support.v7.widget.CardView 
    android:id="@+id/cv_store_offer_display" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 


     <ImageView 
      android:id="@+id/img" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:scaleType="fitXY"/> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/txt" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Foo FOO"/> 

     </LinearLayout> 
    </LinearLayout> 

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

我想知道如何在加載圖像/文本之前讓我的Recyclerview顯示視圖。我正在使用畢加索加載圖像。用於顯示RecyclerView內容的mikepenz FastAdapter。

我還試圖用一個進度條爲https://stackoverflow.com/a/12342168/371557提及。但即使可見性設置爲可見,進度條也不會顯示。

+1

你能不能只指定在XML的形象呢? '機器人:SRC =「@繪製/佔位符」' – StuStirling

+0

你能證明你的代碼中設置圖像畢加索.. –

+0

設置'''機器人:SRC =「@繪製/佔位符」'''使它看起來靜態..因此,我想顯示一個進度條:)任何其他想法? –

回答

4

,你可以使用類似

picasso.load(url) 
    .placeholder(R.drawable.place_holder) 
    .into(imageView); 
+0

感謝您的回答約翰。是否有可能將動畫對象設置爲佔位符? –

+1

是的,你可以繪製的是像'<動畫,旋轉的xmlns:安卓= 「http://schemas.android.com/apk/res/android」 機器人:可繪製= 「@繪製/ progress_image」 機器人:pivotX = 「50%」 機器人:pivotY = 「50%」/>' –

+0

一些奇怪的原因,我的recyclerview是怪怪的。它實際上從不加載佔位符圖像。它在佔位符和URL之間的圖像之間切換,只是在分秒之差。直到那時UI才顯示沒有RecyclerView的標誌 –

1
  <!--You Would Apply Like this--> 
       Picasso.load(url) 
           .placeholder(R.drawable.img_place_holder) 
           .into(imageView); 

     <!--Use ProgressBar--> 
        <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        > 
     <android.support.v7.widget.RecyclerView 
       android:id="@+id/recycler_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/sliding_popup_window" 
       android:layout_below="@+id/bank_info_toolbar" 
       > 

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

      <ProgressBar 
       android:id="@+id/progressBar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       /> 
    </RelativeLayout> 

//Your ProgressBar code 
class Synch extends AsynchTask<void, void, void> { 
    public void onPreExecute() { 
     //your code 
     progressBar.setVisibility(View.VISIBLE); 
     recyclerView.setVisibility(View.GONE); 
    } 
    } 

    public void doinBackground() { 
    //Your Code 
    } 

    public void onPostExecute() { 
    progressBar.setVisibility(View.GONE); 
    recyclerView.setVisibility(View.VISIBLE); 
    }