Example of a usage of Android--viewgroup (reproduced)

Source: Internet
Author: User

Looked for a long time, finally found.

XML code
  1. <? XML version= "1.0" encoding="UTF-8" ?>
  2. <merge xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:okcancelbar="Http://schemas.android.com/apk/res/com.example.android.merge">
  4. <ImageView
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. android:scaletype="center"
  8. android:src="@drawable/golden_gate"
  9. />
  10. <Com.example.android.merge.OkCancelBar
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:layout_gravity="Bottom"
  14. android:paddingtop="8dip"
  15. android:gravity="Center_horizontal"
  16. android:background="#AA000000"
  17. okcancelbar:oklabel="Save"
  18. okcancelbar:cancellabel="Don ' t save"
  19. />
  20. </Merge>

Com.example.android.merge.OkCancelBar is a custom group

Java code
  1. Public class Okcancelbar extends linearlayout{
  2. Public Okcancelbar (Context context,attributeset attrs) {
  3. Super (context, attrs);
  4. SetOrientation (horizontal);
  5. Setgravity (Gravity.center);
  6. Setweightsum (1.0f);
  7. Layoutinflater.from (context). Inflate (R.layout.okcancelbar, this,true);
  8. TypedArray array= context.obtainstyledattributes (attrs, R.styleable.okcancelbar,0,0);
  9. String text= array.getstring (R.styleable.okcancelbar_oklabel);
  10. if (text==null) text="OK";
  11. (Button) Findviewbyid (R.ID.OKCANCELBAR_OK)). SetText (text);
  12. text= array.getstring (R.styleable.okcancelbar_cancellabel);
  13. if (text==null) text="Cancel";
  14. (Button) Findviewbyid (R.id.okcancelbar_cancel)). SetText (text);
  15. Array.recycle ();
  16. }
  17. }

Layoutinflater.from (context). Inflate (r.layout.okcancelbar,this,true);

Get a view from the XML directly into the current group

Okcancelbar.xml:

XML code
  1. <merge xmlns:android="http://schemas.android.com/apk/res/android">
  2. <include layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_ok"/>
  3. <include layout="@layout/okcancelbar_button" android:id="@+id/okcancelbar_cancel" />
  4. </Merge>

Example of a usage of Android--viewgroup (reproduced)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.