I am trying to create some modular user interface elements described in Android Developers - Creating reusable user interface components , unfortunately, I do not get the desired result. The article says:
You can override all layout options. This means that any android: layout_ * attribute can be used with a tag.
My XML code looks like this (relevant parts):
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <include android:id="@+id/radio_group" layout="@layout/radio_buttons" android:layout_marginTop="75dp" /> <include android:id="@+id/player_group" layout="@layout/player_buttons" android:layout_alignParentBottom="true" /> <EditText android:id="@+id/text_field" android:singleLine="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Enter Your Login ID:" android:layout_below="@id/player_group" />
Here is the first of the included layouts:
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/radio_group" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_marginTop="20dp" android:layout_marginLeft="20dp" android:layout_marginBottom="20dp" > <RadioButton android:id="@+id/radio01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Song #1" android:paddingLeft="45dp" /> [two more identical buttons] <TextView android:id="@+id/choice" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="you have selected:"/> </RadioGroup>
and the other:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:text="btn01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" /> <Button android:text="@+id/Button02" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" /> <Button android:text="Start Playing" android:id="@+id/startPlayerBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:onClick="doClick" /> </LinearLayout>
Unfortunately, this leads to all included user interface elements grouped with each other on top of the screen. The EditText element is aligned correctly, but none of the included elements will respond to any overridden attributes. I tried several different ones with the same non-results.
Note. I also tried putting the android:layout_alignParentBottom="true" parameter in the included layouts, thinking that maybe it should be there so that it was overridden, but got the same result.
also - marginTop parameter does nothing.
So - any idea what I'm doing wrong? It drives me crazy!
Note. Some time ago, a question was asked about how the style included layouts, the answer was a link to a page with reusable interface components. I just want to say that I read this question and answer, and it did not help.