在平板电脑和手机的Android图像 [英] Android image on tablets and phones
本文介绍了在平板电脑和手机的Android图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题,L提出申请和L想要的图像进行屏幕(10寸平板电脑和5英寸的手机)。例如升同一部分要像走半宽的平板电脑和手机...我知道LDPI华电国际xhdpi,但是这不是work.Can,你能帮我吗?
I have problem,l make application and l want images take same part of screen(10inch tablet and 5inch phone).For example l want image take half width on tablet and on phone...I know for ldpi hdpi xhdpi,but this not work.Can you help me?
推荐答案
我的标准尺寸图像是320×200(手机),我将它们存储在MDPI目录。对于平板电脑我调整它们的大小,以480 300这样的:
My standard size images are 320 by 200 (for phones) and I store them in the mdpi directory. For tablets I resize them to 480 by 300 like this:
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);
}
}
我做这种方式,因为我有很多图片,我不想存储和维护每一个的两个副本。
I do it this way because I have many images and I do not want to store and maintain two copies of each.
这篇关于在平板电脑和手机的Android图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文