2011-07-23 119 views
4

我剛剛開始使用android開發,並且需要有關背景圖像的幫助。我希望能夠擁有背景圖片,然後在佈局的頂部覆蓋其他項目(按鈕,文本等)。我只是爲了簡單起見而使用了LinearLayout,因爲目前我不知道什麼是最適合我的。爲Android應用程序創建背景圖像 - Java

反正,我不能得到的圖像使用以下代碼來顯示:

import android.app.Activity; 
import android.graphics.Color; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.widget.*; 

public class NewGameActivity extends Activity { 


    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    LinearLayout ll = new LinearLayout(this); 
    ll.setBackgroundDrawable(Drawable.createFromPath("/assets/images/androidBackground.png")); 
    this.setContentView(ll); 
    } 
} 

回答

1

是,如果你使用的是XML,然後發現的LinearLayout的ID喜歡

ll=(LinearLayout)findViewById(R.id.linear1) 

然後設置其背景爲

ll.setBackgroundResource(R.drawable.image_name); 

人在這裏爲這裏給出你的代碼,你可以直接去

ll.setBackgroundResource(R.drawable.image_name); 
相關問題