在Android中实现背景图片自适应的方法有几种,可以根据具体情况选择使用以下其中一种或多种方法:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background_image"
android:scaleType="fitXY"/>
InputStream is = getResources().openRawResource(R.drawable.background_image);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
int imageWidth = options.outWidth;
int imageHeight = options.outHeight;
options.inSampleSize = calculateInSampleSize(options, imageViewWidth, imageViewHeight);
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
imageView.setImageBitmap(bitmap);
Glide.with(context)
.load(R.drawable.background_image)
.centerCrop()
.into(imageView);
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: android jnilibs能支持哪些功能