맞춤 이미지를 만들었습니다 ImageView
- 인터넷에서 이미지를 가져 오는 것이 목적입니다.맞춤 이미지 뷰어
public class WebImageView extends ImageView {
private String mUrl;
private Bitmap mCachedBitmap;
public String getUrl() { return mUrl; }
public void setUrl(String url) {
mUrl = url;
if (mCachedImage == null) {
new ImageDownloader(this).execute(mUrl);
} else {
setImageBitmap(mCachedImage);
}
}
public WebImageView(Context context) {
super(context);
}
public WebImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public WebImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public WebImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
private class ImageDownloader extends AsyncTask<String, Void, Bitmap> {
private final ImageView mView;
public ImageDownloader(ImageView view) {
mView = view;
}
@Override
protected Bitmap doInBackground(String... params) {
String url = params[0];
Bitmap image = null;
try {
InputStream in = new java.net.URL(url).openStream();
image = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error Message", e.getMessage());
e.printStackTrace();
}
return image;
}
protected void onPostExecute(Bitmap result) {
mView.setImageBitmap(result);
}
}
}
을 그리고 그것은 사용이 매우 간단입니다 : 그것은의 선언은 다음과 같습니다
<com.myapp.views.controls.WebImageView
android:layout_width="@dimen/restaurantLogoWidth"
android:layout_height="@dimen/restaurantLogoHeight"
url="@{restaurant.model.logoUrl}"
style="@style/ImageView" />
위의 XML은 android.support.v7.widget.RecyclerView
내부에 배치됩니다. 문제는 내 항목 목록에서 스크롤 할 때 (또는 일부 애니메이션을 수행 할 때) 끔찍한 결과를 초래한다는 것입니다. 즉, 스크롤 (또는 애니메이션)이 원활하지 않다는 것을 의미합니다. 어떤 조언을 더 잘하려면 여기를 바꿀 수 있습니까?
내 조언은 [안드로이드에서 사용할 수있는 기존의 많은 이미지 로딩 라이브러리] 중 하나를 (사용하는 것입니다 http://android-arsenal.com/tag/ 46), 바퀴를 다시 재 - 다시 - 다시 - 다시 - 다시 - 다시 발명하지 않고. 그 외에, 당신은'targetSdkVersion'이 13 이상이라고 가정하고, 당신은 싱글 쓰레드입니다. – CommonsWare