2017-03-23 6 views
0

이미지와 텍스트를 표시 할 ScrollView 안에 ListView가 있습니다. 텍스트가 완벽하게 표시됩니다. 그러나 이미지는 그렇지 않습니다. 목록을 천천히 스크롤하면 모든 이미지가 완벽하게로드됩니다.하지만 실제로 빠르게 실행하면로드되지 않습니다. 나는 내가 어떻게이 메소드를 호출하는지 설정하는 방법이라고 생각하지만 이것은 Android에서의 첫날입니다. 아래는 리소스, 레이아웃 및 클래스입니다.안드로이드 ListView 내부 ScrollView 이미지를로드하려면 글라이드 항상 로딩되지 않습니다.

<?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이 사진과 함께 줄을 텍스트 만있는 내가 텍스트와 목록 내부 이미지 뷰를 추가하는 방법

이름. 또한 활동이 목록을로드 할 때 표시되는 모든 "셀"은로드되지 않지만 천천히 아래로 스크롤하여 백업하면 이미지가 나타납니다 (천천히 스크롤하면).

내가 더 많은 정보를 게시해야하는 경우. 안드로이드가 어떻게 작동하는지 아직도 배웁니다.

+1

왜 listview에서 scolling 자체를 관리 할 때 ListView를 scrollview에 넣을까요? .diskCacheStrategy (DiskCacheStrategy.SOURCE);를 시도 했습니까? – Geek

+0

더 나은 결과를 얻으려면 RecyclerView 대신 ListView를 사용하거나 ListView 만 사용하려면 목록 어댑터 클래스에서 ViewHolder를 사용하십시오. – DkThakur

답변

1

try, 글로벌 변수 대신 getImage에 매개 변수로 imageview를 제공합니다. 예 :

// inside getView 
    ImageView imageView = (ImageView) rowView.findViewById(R.id.img); 
    getImages(position, imageView); 

    // GetImage 
    public void getImages(Integer position, ImageView im) { 
     .... 
    } 
+0

이것은 완벽하게 작동했습니다! – Torewin

+0

@Torewin 해피 코딩 – UdeshUK

1

우선, 당신의 목록에 ViewHolder 패턴을 구현하거나 RecyclerView을 사용하는 것이 좋다. 현재 상황에서는보기가 너무 복잡해지면 앱의 성능이 저하 될 수 있으므로 뷰를 계속 팽창시키고 있습니다. ViewHolder 패턴에 대한 자세한 내용을 볼 수 있습니다. here

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    ViewHolder holder; 
    if (convertView == null) { 
     //Inflate the view once if the view is null 
     LayoutInflater inflater = context.getLayoutInflater(); 
     convertView = inflater.inflate(R.layout.someClass, null, true); 
     holder = new ViewHolder(); 
     holder.txtTitle = (TextView) convertView.findViewById(R.id.txt) 
     holder.imageView = (ImageView) convertView.findViewById(R.id.img); 
     convertView.setTag(holder); 
    } 
    else { 
     //retrieve the reference of the inflated view 
     holder = (ViewHolder) convertView.getTag(); 
    } 

    holder.txtTitle.setText(web.get(position)); 
    getImages(holder.imageView, position); 
    return convertView; 
} 

public void getImages(ImageView imageView, int 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); 
     } 
    }); 
} 

static class ViewHolder { 
    TextView txtTitle; 
    ImageView imageView; 
} 
+0

이 정보를 제공해 주셔서 감사합니다. 돌아가서 모든 정보를 다시 작성하고 구조화 할 때이 메서드를 사용합니다. 지금 당장 작업 모델을 얻고 있습니다. – Torewin