标签:android blog http java 文件 width
项目中有个图片在平板电脑中显示特别小的原因,一直苦于没找到原因,也没有平板电脑测试,今天找了个修改分辨率的,编写相关方法终于处理了,记录下比较:if (file.exists()) { // 如果文件已经存在,直接返回 Drawable drawable = Drawable.createFromPath(savePath); DisplayMetrics dm = new DisplayMetrics(); //获取手机屏幕分辨率 dm = context.getResources().getDisplayMetrics(); //屏幕实际大小 // int screenWidth = dm.widthPixels; // int screenHeight = dm.heightPixels; float density = dm.density; //图片实际大小 int imgWidth = (int) (drawable.getIntrinsicWidth() *density); int imgHeight = (int)( drawable.getIntrinsicHeight() * density); //drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, imgWidth,imgHeight); //} return drawable; }
没有图片时加载
private void setDrawable(Drawable nDrawable) { drawable = nDrawable; //drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); //setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); DisplayMetrics dm = new DisplayMetrics(); //获取手机屏幕分辨率 dm = context.getResources().getDisplayMetrics(); //屏幕实际大小 // int screenWidth = dm.widthPixels; // int screenHeight = dm.heightPixels; float density = dm.density; //图片实际大小 int imgWidth = (int) (drawable.getIntrinsicWidth() *density); int imgHeight = (int)( drawable.getIntrinsicHeight() * density); //drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, imgWidth,imgHeight); setBounds(0, 0, imgWidth, imgHeight); //注意加上,不加会出现图片和文字混淆在一起 }原文地址:http://hongshengpeng.com/article/show/254.aspx
Android获取图片实际大小兼容平板电脑,码迷,mamicode.com
标签:android blog http java 文件 width
原文地址:http://blog.csdn.net/hongshengpeng/article/details/24673397