2016-12-16 16 views
2

私はRecyclerViewを表示しようとしていますが、最初にスケルトンビューを読み込み、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コンテンツを表示するためのmikepenz FastAdapter

また、https://stackoverflow.com/a/12342168/371557で説明したようにプログレスバーを使用しようとしました。可視性がVISIBLEに設定されていても、プログレスバーは表示されませんでした。

+1

のようなものを使用することができますか? '' android:src = "@ drawable/placeholder" ' – StuStirling

+0

ピカソで画像を設定する場所をコードで表示することができますか? –

+0

' '' android:src = "@ drawable/placeholder" '' 'は静的に見せます。したがって、私はプログレスバーを表示したいと思った:)他のアイデアは? –

答えて

4

あなたがいないだけで、あなたのXMLで画像を指定することができ

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

ジョンさんにお返事ありがとうございます。アニメーションオブジェクトをプレースホルダとして設定することは可能ですか? –

+1

はい、描画可能なものは、 ' ' –

+0

私のリサイクルマシンビューは変わったところがあります。実際にはプレースホルダ画像はロードされません。分割された2番目の違いだけで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); 
    } 
関連する問題