Dynamisches vs XML-Layout in Android?
Ich bin neu in der Android-Entwicklung und habe angefangen, meine eigene Benutzeroberfläche zu erstellen. Ich sehe, dass Sie es entweder dynamisch so etwas erstellen können (Dynamische Layouts):
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
TextView tv = new TextView(this);
tv.setText("Name");
ll.addView(tv);
EditText et = new EditText(this);
ll.addView(et);
Button b = new Button(this);
b.setText("Ok");
ll.addView(b);
}
aber ich sehe auch, dass netbeans eine datei hatRessourcen-> Layout-> main.xml. So können Sie ein XML-Layout für die Benutzeroberfläche erstellen (XML-Layout deklarieren):
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, AndroidTest"
/>
</LinearLayout>
Meine Frage ist also, welche soll ich verwenden? Was wird empfohlen und was sind die Vor- und Nachteile von dynamischen vs XML-Layouts in der Android-Entwicklung?