2011-10-24 7 views
0

我正在嘗試將背景圖像放在我的偏好活動上,並且我想動態地製作它。如何從我的PreferencesActivity類中獲取對我的contentView的引用?

這是我的代碼(在PrefrenceActivity類的OnCreate):

// Set the background image 
    Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.spash_bk); 
    BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp); 
    bitmapDrawable.setAlpha(100); 
    LinearLayout layout = (LinearLayout) *** here i need the layout *** 
    layout.setBackgroundDrawable(bitmapDrawable); 

什麼,我缺少的是:誰可以進入佈局的參考,所以我可以執行的操作?

由於提前, 利奧爾

回答

1

您必須佈局給出一個ID爲.xml類

<LinearLayout 
    android:id="@+id/my_layout_id" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:gravity="center"> 

...

後清潔和建立你項目。

然後更換線

的LinearLayout佈局=(的LinearLayout)**這裏我需要的佈局**

的LinearLayout佈局=(的LinearLayout)findViewById( R.id.my_layout_id);

相關問題