Android图片等比例缩放和填充屏幕效果

这篇文章主要为大家详细介绍了Android图片等比例缩放和填充屏幕效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Android图片等比例缩放和填充屏幕的具体代码,供大家参考,具体内容如下

第一种方法:在ImageView的t同事设置两个属性

 android:adjustViewBounds="true" android:scaleType="fitXY

第二中方法:用IamgeView的 android:scaleType  设置属性的时候  填充屏幕出现的各种问题

 /** * 将图片等比例缩放 setAdjustViewBounds setMaxWidth setMaxWidth必须同时设置才有效 * * @param context * @param view *   父容器 * @param image *   图片控件 * @param source *   图片资源 */ public static void setImageViewMathParent(Activity context, LinearLayout view, ImageView image, int source) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), source); DisplayMetrics displayMetrics = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay() .getMetrics(displayMetrics); float scalew = (float) displayMetrics.widthPixels / (float) bitmap.getWidth(); image.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); image.setAdjustViewBounds(true); if (displayMetrics.widthPixels  bitmap.getHeight() ? displayMetrics.heightPixels : bitmap.getHeight(); image.setMaxWidth((int) ss); view.addView(image); if (bitmap != null && bitmap.isRecycled()) { bitmap.recycle(); } } 

以上就是Android图片等比例缩放和填充屏幕效果的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 移动