2016-09-05 6 views
-3

퀴즈 게임이며 대답은 텍스트 또는 이미지 일 수 있습니다. 길드 ​​이미지를 사용하여로드하지만 일부 사용자의 경우 인터넷이 좋더라도 이미지를로드 할 수 없습니다. 이미지 품질이 낮습니다.글라이드 이미지가 가끔로드되지 않습니다.

나는 길드 문제인지 아닌지 전혀 모르므로 모든 코드를 복사합니다.

if (AppConstant.arQuestionList.get(questionid).getArAnswer().get(i).getAtype() 
        .equalsIgnoreCase("image")) { 
       txtOption = new ImageView(this); 

       try { 
        Glide.with(QuestionActivity.this).load(AppConstant.arQuestionList.get(questionid) 
          .getArAnswer().get(i).getAnswer()).override(60, 60).into((ImageView) 
          txtOption); 
       }catch (OutOfMemoryError e){ 
        e.printStackTrace(); 
       } 
       txtOption.setPadding(5, 5, 5, 5); 

      } else { 
       txtOption = new TextView(this); 

       ((TextView) txtOption).setText(AppConstant.arQuestionList.get(questionid) 
         .getArAnswer().get 
           (i).getAnswer()); 
       ((TextView) txtOption).setTextColor(getResources().getColor(R.color.answer_color)); 
       ((TextView) txtOption).setTypeface(tf, Typeface.BOLD); 
       ((TextView) txtOption).setGravity(Gravity.CENTER); 
       txtOption.setPadding(10, 20, 10, 20); 
      } 

레이아웃

<LinearLayout 
     android:id="@+id/answerwrap" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/dp_30" 
     android:layout_marginRight="@dimen/dp_30" 
     android:layout_marginTop="@dimen/dp_30" 
     android:orientation="vertical"> 

    </LinearLayout> 

답변

2

내가 여기 설명하고 글라이드를 사용하는 가장 좋은 방법.

//crete this method into your Utils class and call this method wherever you want to use. 
//you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method. 
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) { 
    if (context == null || context.isDestroyed()) return; 

    //placeHolderUrl=R.drawable.ic_user; 
    //errorImageUrl=R.drawable.ic_error; 
     Glide.with(context) //passing context 
       .load(getFullUrl(url)) //passing your url to load image. 
       .placeholder(placeHolderUrl) //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. 
       .error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is. 
       .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); //pass imageView reference to appear the image. 
} 

fade_in.xml (RES-> ANIM에 넣어)

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<!--THIS ANIMATION IS USING FOR FADE IN --> 

<alpha 
    android:duration="800" 
    android:fromAlpha="0.0" 
    android:interpolator="@android:anim/decelerate_interpolator" 
    android:toAlpha="1.0" /> 

그리고 마지막으로이 방법 당신의 활동에서

를 호출합니다. 당신의 조각에서

Utils.loadImage(YourClassName.this,mImageView,url,R.drawable.ic_user,R.drawable.ic_error); 

또는

Utils.loadImage(getActivity,mImageView,url,R.drawable.ic_user,R.drawable.ic_error); 
+0

시도했지만 여전히 작동하지 않습니다. –

1

나는 모든 것을 따랐다.

추가 .dontAnimate 추가 필요한 모든 권한, 인터넷,

ACCESS_NETWORK_STATE

그러나 아무것도 작동하지 않습니다.

마지막으로 이미지로드 이유를 찾지 못했습니다. 내 이미지 URL에 http 또는 https이 없습니다. 내 이미지 URL 앞에 http://을 추가 했으므로 완벽하게로드됩니다.

관련 문제