我有一些图像文件,这些文件将在Android的ImageViews中使用。现在是MDPI。我创建了新的ImageViews,但IDE使它们比我需要的更小,所以对于MDPI,我有一个更小的图像。如何返回正常大小的图像?如果在res/drawable mdpi中手动更改此文件,则不会发生任何事情,在布局中图像较小。也许我可以用它从所有文件中删除这些资源?为什么在res/drawable mdpi中替换图像没有任何效果?
第一张图片在这里。需要在下面添加4。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#45010D">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/radio" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/???" /> // here ??? must be the name of second image and it must be under the first.
</LinearLayout>
我将所有图像存储在MDPI目录中,然后使用以下代码为平板电脑调整图像大小:
if (isTablet(getActivity())){ // tablets only
debugLog( "display tablet image="+imagename);
int resID = getResources().getIdentifier(imagename,"drawable", getActivity().getPackageName()); // the corresponding resource id
if (resID != 0) {
Bitmap bmp=BitmapFactory.decodeResource(getResources(), resID);
int width=480;
int height=300;
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
ImageView imageView = (ImageView) getActivity().findViewById(R.id.tablet_image); // the imageview to change
//imageView.setImageResource(resID);
imageView.setImageBitmap(resizedbitmap);
}
}
希望这能有所帮助。