我尝试在 gridview.bt 中使用我无法获得的整数值图像。
这是我的价值观/string.xml
<integer-array name="anim">
<item >@drawable/goat1</item>
<item >@drawable/lamb1</item>
<item>@drawable/bear</item>
<item>@drawable/lion</item>
</integer-array>
这是我的java代码:
公共类 GridViewActivity 扩展 Activity {
**int[] anim=getResources().getIntArray(R.array.anim);**
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
}
}
公共类 ImageAdapter 扩展 BaseAdapter { 私有上下文 mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(anim[position]);
return imageView;
}