You do not know what you are talking about. XSLT rulez (see the FAQ).
But I was not referring to that. Rather, in Android app development, XML
layouts are “inflated” into widget object hierarchies. For example:
@Override
public ArticleViewHolder onCreateViewHolder(ViewGroup viewGroup,
int viewType) {
Context context = viewGroup.getContext();
int layoutIdForListItem = R.layout.selector_list_item;
LayoutInflater inflater = LayoutInflater.from(context);
boolean shouldAttachToParentImmediately = false;
View view = inflater.inflate(layoutIdForListItem, viewGroup,
shouldAttachToParentImmediately);
ArticleViewHolder viewHolder = new ArticleViewHolder(view);
return viewHolder;
}
Then there is a file res/layout/selector_list_item.xml that contains the
layout for a list item. It looks like this:
--------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Horizontal linear layout to create a contacts list item -->
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:gravity="center_vertical">
<!-- Person icon -->
<ImageView
android:id="@+id/personIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_person"
android:paddingRight="4dp"
android:paddingLeft="4dp"
android:contentDescription="@string/person_icon"/>
<!-- Text views for a person's first and last name -->
<TextView
android:id="@+id/firstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="@android:color/black"
android:text="@string/first"
android:paddingRight="4dp"
android:paddingLeft ="4dp"/>
[…]
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
</LinearLayout>
--------------------------------------------------------------------------
IMHO, that approach produces very clean code¹. It could be used in
ECMAScript-based Web applications as well. That is, the *validateable*
markup defines the layout, script code reads the markup and converts it to
description objects, and other script code produces a document fragmnt with
elements having specific behaviors (widgets). The layout in XML allows to
design it with a graphical editor as well (indeed, XSLT could be used to
make SVG out of it) almost independent of the final presentation. The
intermediary step would allow to adapt or entirely build the layout in
script code without having to deal with the details of the DOM.
______
¹ The above can still be improved; it is exercise code where the student
is supposed to replace all hard-coded values with resource references for
achieving a unified layout throughout all “activities” of the app.