我正在使用來自YouTube的服務,它向我返回一個URL。通過這個URL,我可以繼續使用NetworkImageView。問題是,圖像不佔用所有我定義字段NetworkImageViewVolley不能正確調整圖像大小
我的URL
https://i.ytimg.com/vi/2HA41DV_K7s/hqdefault.jpg
XML
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/banner_channel"
android:layout_width="120dp"
android:layout_height="90dp"
android:scaleType="centerCrop"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" />
</LinearLayout>
在我的適配器
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Context ctx = parent.getContext();
if (convertView == null) {
convertView = LayoutInflater.from(ctx).inflate(LAYOUT, null);
}
NetworkImageView img = (NetworkImageView) convertView.findViewById(R.id.banner_channel);
img.setImageUrl(mVideoList.items.get(position).snippet.thumbnails.high.url, VolleySingleton.getInstance(
ctx).getImageLoader());
img.setDefaultImageResId(R.drawable.channel_thumb_default);
return convertView;
}
類的空間緩存
/**
* Created by Douglas on 24/08/2014.
*/
public class VolleySingleton {
private static VolleySingleton mInstance = null;
// Fila de execução
private RequestQueue mRequestQueue;
// Image Loader
private ImageLoader mImageLoader;
private VolleySingleton(Context context) {
mRequestQueue = Volley.newRequestQueue(context);
mImageLoader = new ImageLoader(this.mRequestQueue, new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10);
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
});
}
public static VolleySingleton getInstance(
Context context) {
if (mInstance == null) {
mInstance = new VolleySingleton(context);
}
return mInstance;
}
public RequestQueue getRequestQueue() {
return this.mRequestQueue;
}
public ImageLoader getImageLoader() {
return this.mImageLoader;
}
}
圖片我的名單
的什麼是你希望看到的是沒有發生多少?對我來說,就像120x90調整圖像大小一樣。 – jlmcdonald 2014-09-04 01:15:35