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?
What are the maintainability benefits of using XML for this?
What are the performance benefits of using XML for this?
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.
You may refer to Why using XML to create GUI is a good practice in Android.
For me, I feel this is more like personal taste. I came from Java Swing background. When I am doing desktop app development, I prefer to create GUI programmatic.
However, when comes to Android development, I will stick to XML based GUI development, although I favour to use code instead of XML.
This is because, I tend to follow the majority favoured coding style and mythology, which makes me easy to get technical support and tutorials.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With