平板电脑和手机上的 Android 图像 [英] Android image on tablets and phones

查看:21
本文介绍了平板电脑和手机上的 Android 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我制作应用程序并且我希望图像占据屏幕的同一部分(10 英寸平板电脑和 5 英寸手机).例如,我希望图像在平板电脑和手机上占据一半宽度......我知道 ldpi hdpi xhdpi,但这不起作用.你能帮我吗?

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 x 200(用于手机),我将它们存储在 mdpi 目录中.对于平板电脑,我将它们调整为 480 x 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆