获取参数的方法我有方法来调整图像,我想从阵列参数,但它一直显示错误说如何从阵列
incompatible types
found int
required android.graphics.drawable.Drawable
这是我的方法
public Drawable ResizeImage (int imgResize){
Display imgPost = getWindowManager().getDefaultDisplay();
double dvcWidth = imgPost.getWidth();
BitmapDrawable imgBD = (BitmapDrawable)this.getResources().getDrawable(imgResize);
double imgHeight = imgBD.getBitmap().getHeight();
double imgWidth = imgBD.getBitmap().getWidth();
double imgRatio = dvcWidth/imgWidth;
int newImgHeight = (int) (imgHeight*imgRatio);
Bitmap imgBmap = BitmapFactory.decodeResource(getResources(),imgResize);
Drawable imgDrawable = new BitmapDrawable(this.getResources(),getResizedBitmap(imgBmap,newImgHeight,(int) dvcWidth));
return imgDrawable;
}
我的数组
int[] imgDvc= new int[]{
ResizeImage(R.drawable.pc),
R.drawable.ps4,
R.drawable.xbone
}
,我打电话给我的阵列通过这里
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<10;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("Dvc", Integer.toString(imgDvc[i]));
aList.add(hm);
}
String[] game= {"Dvc"};
我用它来填充listview,谢谢你的回答。
代码中的哪行代表错误指的是? –
@MehmetKologlu this ResizeImage(R.drawable.pc)line。 – sh4man
哦,我现在看到它。你已经声明了一个int数组,但你试图在其中添加一个'Drawable'。你不能这样做。 –