setBackgroundColor(int couleur) et RelativeLayout

Lorsque j'ai utilisé ce fichier XML...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"

tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:text="@string/hello_world" />

</RelativeLayout>

..Je vois que la couleur d'arrière-plan envelopper le contenu

http://img716.imageshack.us/img716/8225/rlayout.jpg

Mais si j'écris ce RelativeLayout par code...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    RelativeLayout layout = new RelativeLayout(this);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);


    layout.setBackgroundColor(Color.parseColor("#FF0000"));

    TextView text = new TextView(this);
    text.setText("Hello world");

    //Añado texto
    layout.addView(text);

    layout.setLayoutParams(params);

    setContentView(layout); 
}

...Je vois que la couleur d'arrière-plan de match parent au lieu d'envelopper le contenu

http://img404.imageshack.us/img404/1427/rlayoutfull.jpg

Des idées?

Merci!

InformationsquelleAutor Bae | 2013-03-23