setBackgroundColor(int Farbe) und RelativeLayout
Wenn ich diese XML-Datei...
<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>
..Ich sehe, dass die Hintergrundfarbe wrap Inhalt
http://img716.imageshack.us/img716/8225/rlayout.jpg
Aber wenn ich das Schreibe, RelativeLayout von 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);
}
...Ich sehe, dass die Hintergrundfarbe übereinstimmen Elternteil anstelle von wrap-content
http://img404.imageshack.us/img404/1427/rlayoutfull.jpg
Irgendwelche Ideen?
Dank!
InformationsquelleAutor Bae | 2013-03-23
Du musst angemeldet sein, um einen Kommentar abzugeben.
sind Sie nie die Einstellung des layout params:
und ich denke, dass sollte der:
sowie alle anderen anzeigen, die Sie hinzufügen, um Ihr layout, bevor Sie die Einstellung der layout params, sonst gibt es keine Inhalte zu wrap-around.
Edit:
was passiert, wenn Sie gesetzt werden:
?
siehe aktualisierte Antwort.
Ich habe vergessen " - layout.setLayoutParams" ! Nun habe ich versucht, hinzuzufügen textview zu RelativeLayout und fügen Sie dann params, relativelayout, aber ich bekomme das gleiche Ergebnis :S
siehe aktualisierte Antwort.
Die gleichen, die Alle Bildschirm ist rot. Ich denke, die haben keine Wirkung, da wollte ich mit 300px Breite und Höhe, und ich sehe auch alle Bildschirm rot :S
InformationsquelleAutor Emil Adz