我剛剛開始使用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);
}
}
謝謝,我只是想出瞭如何在XML中做到這一點。 – HJM