2010-08-31 40 views
2

我試圖重現這個簡單的佈局行爲創建佈局:不同的行爲使用XML/JAVA

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#0000ff"/> 


藍色背景採取一切可用的空間的LinearLayout。



我不明白爲什麼這個java代碼不起作用?屏幕保持黑色。有人可以建議嗎?

LinearLayout layout = new LinearLayout(this, null); 
layout.setBackgroundColor(0xff); 
layout.setOrientation(LinearLayout.VERTICAL); 
layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); 
setContentView(layout); 

謝謝。

回答

0

代碼中的0xff是透明的藍色:)使用0xff0000ff。