RecyclerViewに画像がロードされる前にProgress Barを追加するコードを知りたい。ここに私のRecyclerViewAdapterコードがあります。イメージがロードされる前にRecyclerViewの画像をロードするプログレスバー
RecyclerViewAdapter.java
package com.example.rizkafs.laundrize;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
private List<DataLaundry> rvData;
private Context context;
public RecyclerViewAdapter(List<DataLaundry> rvData) {
this.rvData = rvData;
}
public class ViewHolder extends RecyclerView.ViewHolder {
// di tutorial ini kita hanya menggunakan data String untuk tiap item
CardView cv;
public TextView nama;
public TextView alamat;
public TextView jenis;
public ImageView imageVIew;
public ProgressBar progress;
public ViewHolder(View v) {
super(v);
cv = (CardView) v.findViewById(R.id.card_view);
nama = (TextView) v.findViewById(R.id.txt_judul);
alamat = (TextView) v.findViewById(R.id.alamat);
jenis = (TextView) v.findViewById(R.id.jenis);
imageVIew = (ImageView) v.findViewById(R.id.imageView);
progress = (ProgressBar) v.findViewById(R.id.progress);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// membuat view baru
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.laundry_card, parent, false);
// mengeset ukuran view, margin, padding, dan parameter layout lainnya
context = parent.getContext();
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, final int i) {
try {
// - mengambil elemen dari dataset (ArrayList) pada posisi tertentu
// - mengeset isi view dengan elemen dari dataset tersebut
DataLaundry list = rvData.get(i);
holder.nama.setText(list.getNama());
holder.alamat.setText(list.getAlamat());
holder.jenis.setText(list.getJenis());
Log.d("GetData", list.getHarga());
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://laundrize-68cee.appspot.com/");
StorageReference pathReference = storageRef.child(list.getImage_url().get(0));
Glide.with(context)
.using(new FirebaseImageLoader())
.load(pathReference)
.into(holder.imageVIew);
holder.progress.setVisibility(View.GONE);
holder.cv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, DetailsActivity.class);
intent.putExtra("dataLaundry", rvData.get(i));
context.startActivity(intent);
}
});
} catch (Exception e) {
}
}
}
laundry_card.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="11dp"
android:paddingLeft="10dp"
android:paddingRight="11dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/gambar">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/progress"/>
</RelativeLayout>
<TextView
android:id="@+id/txt_judul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/gambar"
android:textSize="17sp"
android:layout_marginTop="12dp"
android:textColor="#000000"
android:text="Judul"/>
<TextView
android:id="@+id/alamat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_below="@id/txt_judul"
android:layout_marginTop="9dp"
android:layout_marginBottom="12dp"
android:layout_marginLeft="7dp"
android:textColor="#000000"
android:text="Alamat"/>
<TextView
android:id="@+id/jenis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:textSize="14sp"
android:layout_below="@id/alamat"
android:layout_marginTop="9dp"
android:layout_marginBottom="12dp"
android:text="Jenis"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
私はすでにプログレスバーを追加しますが、それは動作しませんが、ちょうど空白スペースがあります。上記のインポートコードを削除して、ここに表示されるコードを最小限に抑えます。ありがとう、私の悪い英語のために申し訳ありません。
あなたのレイアウト 'laundry_card'ためのコードを表示することができますか? –
上記の投稿を編集しました –
ProgressBarを使用しないでください。グライドにはローディング時にいくつかのドロウアブルを設定する方法が必要です。プレースホルダは使用できます。 – Selvin