我已将我的drawables保存在资源文件中的整数数组中,但是当我尝试阅读并使用滑动库加载它时,我无法显示图像。
适配器
public class CuisineAdapter extends RecyclerView.Adapter<ViewHolder_Cuisine> {
private Context context;
private TypedArray pictures;
private ArrayList<Integer> images;
public CuisineAdapter(Context context) {
this.context = context;
this.images = new ArrayList<>();
/*images.add(R.drawable.africa);
images.add(R.drawable.bahamas);
images.add(R.drawable.brazil);
images.add(R.drawable.china);
images.add(R.drawable.denmark);
images.add(R.drawable.france);
images.add(R.drawable.germany);
images.add(R.drawable.great_britain);
images.add(R.drawable.greece);
images.add(R.drawable.india);
images.add(R.drawable.ireland);
images.add(R.drawable.israel);
images.add(R.drawable.italy);
images.add(R.drawable.japan);
images.add(R.drawable.korea);
images.add(R.drawable.mexico);
images.add(R.drawable.russia);
images.add(R.drawable.spain);
images.add(R.drawable.thailand);
images.add(R.drawable.united_arab_emirates);
images.add(R.drawable.united_states_of_america);
images.add(R.drawable.vietnam);*/
pictures = context.getResources().obtainTypedArray(R.array.country_flags);
Log.i("data", pictures.toString() + "");
}
@Override
public ViewHolder_Cuisine onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.cuisine_type, parent, false);
return new ViewHolder_Cuisine(view);
}
@Override
public void onBindViewHolder(final ViewHolder_Cuisine holder, int position) {
int image = images.get(position);
Glide.with(context)
.load(image)
.override(150, 150)
.into(holder.getImageView());
//holder.getImageView().setImageResource(image);
}
@Override
public int getItemCount() {
return images.size();
}
}
如果我使用holder.getImageView()。setImageResource(image);而不是滑行一切都很好,我可以显示图像,但这需要大量的记忆,所以我想使用滑行。
<integer-array name="country_flags">
<item>@drawable/africa</item>
<item>@drawable/bahamas</item>
<item>@drawable/brazil</item>
<item>@drawable/china</item>
<item>@drawable/denmark</item>
<item>@drawable/france</item>
<item>@drawable/germany</item>
<item>@drawable/great_britain</item>
<item>@drawable/greece</item>
<item>@drawable/india</item>
<item>@drawable/ireland</item>
<item>@drawable/israel</item>
<item>@drawable/italy</item>
<item>@drawable/japan</item>
<item>@drawable/korea</item>
<item>@drawable/mexico</item>
<item>@drawable/russia</item>
<item>@drawable/spain</item>
<item>@drawable/thailand</item>
<item>@drawable/united_arab_emirates</item>
<item>@drawable/united_states_of_america</item>
<item>@drawable/vietnam</item>
</integer-array>
我尝试使用类型化数组但不成功,所以我转移到了一个arraylist
答案 0 :(得分:0)
我意识到的问题是滑行仅加载光栅图像而不是矢量图像,所以我使用矢量图像库在我的应用程序中加载矢量图像。