Looked for a long time, finally found.
XML code
- <? XML version= "1.0" encoding="UTF-8" ?>
- <merge xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:okcancelbar="Http://schemas.android.com/apk/res/com.example.android.merge">
- <ImageView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaletype="center"
- android:src="@drawable/golden_gate"
- />
- <Com.example.android.merge.OkCancelBar
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="Bottom"
- android:paddingtop="8dip"
- android:gravity="Center_horizontal"
- android:background="#AA000000"
- okcancelbar:oklabel="Save"
- okcancelbar:cancellabel="Don ' t save"
- />
- </Merge>
Com.example.android.merge.OkCancelBar is a custom group
Java code
- Public class Okcancelbar extends linearlayout{
- Public Okcancelbar (Context context,attributeset attrs) {
- Super (context, attrs);
- SetOrientation (horizontal);
- Setgravity (Gravity.center);
- Setweightsum (1.0f);
- Layoutinflater.from (context). Inflate (R.layout.okcancelbar, this,true);
- TypedArray array= context.obtainstyledattributes (attrs, R.styleable.okcancelbar,0,0);
- String text= array.getstring (R.styleable.okcancelbar_oklabel);
- if (text==null) text="OK";
- (Button) Findviewbyid (R.ID.OKCANCELBAR_OK)). SetText (text);
- text= array.getstring (R.styleable.okcancelbar_cancellabel);
- if (text==null) text="Cancel";
- (Button) Findviewbyid (R.id.okcancelbar_cancel)). SetText (text);
- Array.recycle ();
- }
- }
Layoutinflater.from (context). Inflate (r.layout.okcancelbar,this,true);
Get a view from the XML directly into the current group
Okcancelbar.xml:
XML code
- <merge xmlns:android="http://schemas.android.com/apk/res/android">
- <include layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_ok"/>
- <include layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_cancel" />
- </Merge>
Example of a usage of Android--viewgroup (reproduced)