I’ve been through a few tutorials etc and have found that I can acheive the same results defining all of my UI components in code.
For example:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("hello");
LinearLayout ll = new LinearLayout(this);
ll.addView(tv);
setContentView(ll);
}
is the equivalent of
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
+
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
What are the performance/maintainability benefits of using XML for this?
If a programmer prefers to use code over XML what extra considerations should be made?
That all depends on the implementation I suppose. I doubt there are any appreciable performance differences, but I honestly don’t know enough to say definitively what they may be.