如何将不同大小的图片都设置成手机屏幕大小显示

icanfly20000 2010-11-12 04:30:56
如题:如何将不同大小的图片都设置成手机屏幕大小显示
...全文
2153 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
onlyxing 2011-01-07
  • 打赏
  • 举报
回复
给我看看呢
foley_liao 2010-11-25
  • 打赏
  • 举报
回复
帮顶下,上面这么多,难度不能解决问题吗? 我觉得上面的都可以啊
nlove518 2010-11-25
  • 打赏
  • 举报
回复
Java用途广哦~~
icanfly20000 2010-11-25
  • 打赏
  • 举报
回复
求解决方案
icanfly20000 2010-11-23
  • 打赏
  • 举报
回复
还没解决呢 ,求助啊
icanfly20000 2010-11-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 dropwater_yjqbll 的回复:]

用LinearLayout,width和height都设置成固定的值(屏幕大小),把图片设为它的background,图片会随组件大小伸缩,设成imageview的src则不会;
[/Quote]
可是我的是一个动画图片,放在linearlayout中可以吗?
icanfly20000 2010-11-17
  • 打赏
  • 举报
回复
还没解决呢,再顶下,希望高手帮忙
葵花小子 2010-11-17
  • 打赏
  • 举报
回复
用LinearLayout,width和height都设置成固定的值(屏幕大小),把图片设为它的background,图片会随组件大小伸缩,设成imageview的src则不会;
icanfly20000 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhq56030207 的回复:]

引用 3 楼 icanfly20000 的回复:

引用 2 楼 zhq56030207 的回复:

其中,scaleWidth和scaleHeight是欲缩放后的大小,这里加个参数how是防止有不需要缩放的情况

那要怎么做才是屏幕大小呢

先获取屏幕的长度和宽度,然后让图片适配
[/Quote]

你的代码明显有问题啊
纠结的木棉花 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 icanfly20000 的回复:]

引用 2 楼 zhq56030207 的回复:

其中,scaleWidth和scaleHeight是欲缩放后的大小,这里加个参数how是防止有不需要缩放的情况

那要怎么做才是屏幕大小呢
[/Quote]
先获取屏幕的长度和宽度,然后让图片适配
icanfly20000 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhq56030207 的回复:]

其中,scaleWidth和scaleHeight是欲缩放后的大小,这里加个参数how是防止有不需要缩放的情况
[/Quote]
那要怎么做才是屏幕大小呢
纠结的木棉花 2010-11-12
  • 打赏
  • 举报
回复
其中,scaleWidth和scaleHeight是欲缩放后的大小,这里加个参数how是防止有不需要缩放的情况
纠结的木棉花 2010-11-12
  • 打赏
  • 举报
回复

1.

  2.private Bitmap getImageFromAssetFile(String fileName,int how){

  3.Bitmap image = null ;

  4.try {

  5.AssetManager am = game.getAssets();

  6.InputStream is = am.open(fileName);

  7.image = BitmapFactory.decodeStream(is);

  8.is.close();

  9.}catch (Exception e){

  10.}

  11.return zoomImage(image,how);

  12.}

  13.public Bitmap zoomImage(Bitmap bgimage,int how) {

  14.int bmpwidth = bgimage.getWidth();

  15.int bmpheight = bgimage.getHeight();

  16.float scaleWidth=0;

  17.float scaleHeight=0;

  18.Matrix matrix = new Matrix();

  19.if(how==0){

  20.scaleWidth = ((float) width) / bmpwidth;

  21.scaleHeight = ((float) height) / bmpheight;

  22.}else{

  23.scaleWidth=Math.min(width,height)/bmpwidth;

  24.scaleHeight=Math.min(width, height)/bmpheight;

  25.}

  26.private Bitmap getImageFromAssetFile(String fileName,int how){

  27.Bitmap image = null ;

  28.try {

  29.AssetManager am = game.getAssets();

  30.InputStream is = am.open(fileName);

  31.image = BitmapFactory.decodeStream(is);

  32.is.close();

  33.}catch (Exception e){

  34.}

  35.return zoomImage(image,how);

  36.}

  37.public Bitmap zoomImage(Bitmap bgimage,int how) {

  38.int bmpwidth = bgimage.getWidth();

  39.int bmpheight = bgimage.getHeight();

  40.float scaleWidth=0;

  41.float scaleHeight=0;

  42.Matrix matrix = new Matrix();

  43.if(how==0){

  44.scaleWidth = ((float) width) / bmpwidth;

  45.scaleHeight = ((float) height) / bmpheight;

  46.}else{

  47.scaleWidth=Math.min(width,height)/bmpwidth;

  48.scaleHeight=Math.min(width, height)/bmpheight;

  49.}

80,488

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧