The collaborative process between Java files and XML files in Android

Source: Internet
Author: User

  

Android uses an XML layout file to define the interface, not the Java code to define the interface, so all components provide two ways to control the behavior of the component.
1. Time control through XML attributes in an XML layout file
2. Control by invoking methods in Java program code.
In fact, regardless of the way they are used, the nature of their control of Android user interface behavior is exactly the same. Most of the time, the XML attributes that control the UI component have a corresponding method.
For the view class, he is the base class for all UI components, so he contains the XML properties and methods that all components can use.
XML file layout is relatively simple, commonly used several properties to practice the basic no big problem, after all, the format will not change much.
The most common in XML files are these two properties:
The two properties of Android:layout_height and Android:layout_width support these three property values.
1. Fill_parent: Specifies the height, width, and height of the child component and the same width as the parent class container component.
2. Match--parent: The property value is exactly the same as fill_parent and can be substituted for fill_parent.
3. Wrap_content: Specifies the size of the sub-component to be able to wrap its contents exactly.
Let's talk about it. Collaboration between Java file. xml files:
After a view property is written to the XML file, a corresponding ID value is generated within the R file file, which is unique.
. This unique ID value is found in the Java file by the R class name, and then the attribute corresponding to this ID value is set.
So it's done. The Java file is associated with the. xml file.

The collaborative process between Java files and XML files in Android

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.