"Learning Notes" Android custom controls

Source: Internet
Author: User

This article is a summary of "custom controls" in the "first line of code-android" in the study of the Guo Lin great God.

Similar method, if the new method has no particular advantage, I will still use the old method. I've never understood it. Using the package name as a control in the layout file, and not knowing the benefits of this approach, so I have not used it. In the previous contact of the book on the custom control is not explained, I look at the online demo, I also do not feel the advantages of the custom control, so I have always been using the system to control. I have tried to learn custom controls from online search, but no explanation is in place. When I saw the first line of code-android, the first thing I did was to look for an introduction to "use package name as a control". I finally found it.

Custom layouts can be more complex, more consistent with what we expect, and certainly improve our programming efficiency.

Custom controls need to specify the full class name, so we'll start with a new class titlelayout inherited from LinearLayout.

public class Titlelayout (context context, AttributeSet Attrs) {public    titlelayout (context context, AttributeSet Attrs) {        Super (context, attrs);        Layoutinflater.from (context). Inflate (R.layout.title, this);}    }
In this class, we re-linearlayout a constructor with two arguments in it, and this constructor is called when the Titlelayout control is introduced into the layout.

Now that the custom control has been created, we need to add this custom control to the layout file:

<pre name= "code" class= "java" ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"    android:layout_width= "match_parent"    android:layout_height= "match_parent" >    < Com.example.uicustomviews.TitleLayout        android:layout_width= "match_parent"        android:layout_height= "Wrap_ Content ">
    </com.example.uicustomviews.TitleLayout>
</
LinearLayout
>









"Learning Notes" Android custom controls

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.