-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:orientation="vertical"
-
android:background="@drawable/main_background"
-
android:id="@+id/mian_bg"
-
android:scaleType="fitXY"
-
android:gravity="center"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
>
-
<ImageView
-
android:layout_gravity="center"
-
android:src="@drawable/img_main_roll0"
-
android:id="@+id/main_cion"
-
android:layout_width="180dp"
-
android:layout_height="180dp"/>
-
-
</<LinearLayout>
-
-
先擷取圖片控制項:
-
public ImageView imageView;
-
public LinearLayout linearLayout;
-
-
imageView=(ImageView)findViewById(R.id.main_cion);
-
linearLayout=(LinearLayout)findViewById(R.id.mian_bg);
-
應在次Activity銷毀時釋放
-
protected void onDestroy() {
-
super.onDestroy();
-
imageView.setImageBitmap(null);//釋放
-
linearLayout.setBackground(null);
-
System.gc();//通知進行回收
-
}
-
-
使用Bitmap記得不用時調用回收
-
bitmap.recycle();
-
-
-
總結:
-
無論你是在xml中布局使用了:
-
-
android:background ,
-
-
還是在java代碼中調用了:
-
-
setBackground( background );-------API16+
-
-
setBackgroundDrawable( background)--------API16-
-
-
setBackgroundResource( resid)
-
-
的方式去設定了背景圖片.
-
-
使用的時候,請調用一下對應的方法:
-
setBackgroundResource和 android:background → setBackgroundResource(0);
-
-
setBackgroundDrawable( background) → setBackgroundDrawable (null)
-
-
setBackground ( background ) → setBackground ( null )
-
然後再onDestory中調用System.gc();
-