私は画像とテキストを表示するScrollViewの中にListViewを持っています。テキストは完全に表示されます。しかし、イメージはそうではありません。リストをゆっくりとスクロールすると、すべての画像が確実に完全にロードされますが、もし私が本当に速く動くと、ロードされることはありません。私は方法を呼んでいるところをセットアップする方法だと思いますが、これはAndroidでの最初の1日です。以下は、リソース、レイアウト、およびクラスです。Android ListView in ScrollView画像を読み込むためにGlideを読み込みません。FireBaseは常に読み込まれません。
私は、リスト内のテキストとImageViewの追加方法:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="50dp" />
</TableRow>
</TableLayout>
それと一緒に行くためのクラス:
public class someClass extends ArrayAdapter<String>{
private final Activity context;
private final ArrayList<String> web;
ImageView imageView;
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReference();
final ArrayList<Uri> uriList = new ArrayList<>();
public galveon_character_creation_spelllist(Activity context,
ArrayList<String> web) {
super(context, R.layout.someClass, web);
this.context = context;
this.web = web;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.someClass, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web.get(position));
getImages(position);
return rowView;
}
public void getImages(Integer position) {
storageRef.child("FolderRef/" + web.get(position) + ".png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//imageView.setImageURI(null);
//imageView.setImageURI(uri);
Glide.with(getContext())
.load(uri) // the uri you got from Firebase
.placeholder(R.drawable.unknown) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
.diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.fitCenter()//this method help to fit image into center of your ImageView
.into(imageView); //Your imageView variable
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
imageView.setImageResource(R.drawable.unknown);
}
});
}
}
web
は絵に並ぶだけのテキストです名前。アクティビティがリストをロードするときにも、表示されているすべての「セル」は読み込まれませんが、ゆっくりと下にスクロールしてバックアップすると(ゆっくりとスクロールすると)画像が表示されます。
もっと情報を投稿する必要がある場合はできます。まだAndroidの仕組みを学ぶ。
ViewHolderパターンについての詳細を読むことができますか? .diskCacheStrategy(DiskCacheStrategy.SOURCE);を試しましたか? – Geek
より良い結果を得るには、ListViewの代わりにRecyclerViewを使用するか、リストビューのみを使用する場合は、リストアダプタクラスのViewHolderを使用してください。 – DkThakur