Android layout type resources (ii) --- XML, drawable, layout

Source: Internet
Author: User

<? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <person name = "xiaomo" age = "23" gender = "male"> </person> </resources>
Core code in java:

Resources r = getResources (); XmlResourceParser xrp = r. getXml (R. xml. person); try {// if the end of the file is not reached, continue loop while (xrp. getEventType ()! = XmlResourceParser. END_DOCUMENT) {// if it is the start tag if (xrp. getEventType () = XmlResourceParser. START_TAG) {String name = xrp. getName (); // determines whether the tag name is the same as that of personif (name. equals ("person") {counter ++; // obtain the tag attribute and append it to StringBuilder sb. append ("Number" + counter + "user information: \ n"); sb. append ("name:" + xrp. getAttributeValue (0) + "\ n"); sb. append ("age:" + xrp. getAttributeValue (1) + "\ n"); sb. append ("gender:" + xrp. getAttributeValue (2) + "\ n") ;}} else if (xrp. getEventType () = XmlPullParser. END_TAG) {} else if (xrp. getEventType () = XmlPullParser. TEXT) {} xrp. next () ;}// set StringBuilder to the text myTextView of TextView. setText (sb. toString (); myButton. setText ("exit");} catch (XmlPullParserException e) {e. printStackTrace ();} catch (IOException e1) {e1.printStackTrace ();}}

MyImageView = (ImageView) findViewById (R. id. mypic); Resources r = getResources (); Drawable d = r. getDrawable (R. drawable. moto); myImageView. setImageDrawable (d );

<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/plugin" tools: context = ". mainActivity "> <TextView android: id =" @ + id/dimen_text "android: layout_width =" fill_parent "android: layout_height =" @ dimen/text_height "android: textColor = "@ color/white" android: background = "@ color/blue" android: text = "@ string/hello_world"/> </RelativeLayout>

SetContentView (R. layout. main );

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.