Android Control Knowledge Points

Source: Internet
Author: User

First, the introduction of layout

Introduce another layout into the XML file

<include layout= "@layout/xxx"/>

A personal understanding is that a layout is nested in a location in the parent layout.

Second, custom controls

Steps:

2.1 Create a new XML file to customize the control

For example:

    

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:layout_height= "Wrap_content"
Android:layout_width= "Match_parent"
android:orientation= "Horizontal" >
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/button3"
android:layout_weight= "1"
android:layout_gravity= "Center"
Android:layout_margin= "5dip"
Android:background= "#0f0f0f"
Android:textcolor= "#fff000"
android:text= "Back"/>
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
android:gravity= "Center"
Android:textsize= "24SP"
Android:textcolor= "#fff000"
android:layout_weight= "1"
Android:id= "@+id/text2"
android:text= "Wheat barley"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_gravity= "Center"
Android:layout_margin= "5DP"
Android:textcolor= "#fff000"
android:layout_weight= "1"
Android:id= "@+id/button4"
android:text= "Edit"/>

</LinearLayout>

2.2 Create a new class that inherits from the view class or its subclasses. For example:

public class Tittlelayout extends LinearLayout {
Public Tittlelayout (context context, AttributeSet Attrs) {
Super (context, attrs);
((Layoutinflater) This.getcontext (). Getsystemservice (Context.layout_inflater_service)). Inflate (R.layout.button, this);
}
}

2.3 Introducing a control into a layout invokes the control's constructor, overrides the constructor of the custom control's parent class, and loads the XML of the layout file with Layoutinflater in the constructor.
2.4 Adding a custom control to a layout file
Adding a custom control is just like a normal control, except that you need to indicate the full class name of the control.
For example:
<com.example.zds.test_menu01. Tittlelayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>







Android Control Knowledge Points

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.