Android界面背景图片不显示---三星手机

前短时间遇见的一个问题,应用中的一个activity背景图片加载不上,也就是不显示。其他手机都可以,就三星的一款手机不行。

布局界面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:background="@drawable/app_background"
    tools:context="cn.vn.ui.MainActivity" >

</RelativeLayout>

中间的控件就不写了。

修改了一下在应用中加载图片。

@Override
	protected void onResume() {
		super.onResume();
		RelativeLayout layout = (RelativeLayout)findViewById(R.id.main_background);
		InputStream is ;
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		opt.inSampleSize = 2;
		is= getResources().openRawResource(R.drawable.app_background);
		Bitmap bm = BitmapFactory.decodeStream(is, null, opt);
		BitmapDrawable bd = new BitmapDrawable(getResources(), bm);
		layout.setBackgroundDrawable(bd);
	}

这样就可以正常显示背景图片了。

    原文作者:VNanyesheshou
    原文地址: https://blog.csdn.net/VNanyesheshou/article/details/49925535
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞