本文主要是介绍android 图片填充满,高度可变,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
int width = 0;if (Build.VERSION.SDK_INT >= 19){width = activity.getWindow().getWindowManager().getDefaultDisplay().getMode().getPhysicalWidth();}
//并设置图片充满,图片高度变动public static void setImageViewBitmap(ImageView imageView, Bitmap map){imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);if (imageView.getWidth() > 5){float height = (float)imageView.getWidth()/(float)map.getWidth() * (float)map.getHeight();ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();layoutParams.height = (int) height;imageView.setLayoutParams(layoutParams);}imageView.setImageBitmap(map);}//并设置图片充满,图片高度变动public static void setImageViewBitmap(ImageView imageView, Bitmap map,int with){imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);float height = (float)with/(float)map.getWidth() * (float)map.getHeight();ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();layoutParams.width = with;layoutParams.height = (int) height;imageView.setLayoutParams(layoutParams);imageView.setImageBitmap(map);}
这篇关于android 图片填充满,高度可变的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!