Custom view (combined control)

Source: Internet
Author: User

Custom view (combined control)
Java code uses composite controls to implement custom controls. It inherits a ViewGrou object, such as LinearLayout, FrameLayout, RelativeLayout, and so on, copy code 1 public class CombinView extends RelativeLayout {2 3 public CombinView (Context context, AttributeSet attrs) {4 super (context, attrs); 5 LayoutInflater inflater = (LayoutInflater) context. getSystemService (Context. LAYOUT_INFLATER_SERVICE); 6 RelativeLayout layout = (RelativeLayout) inflater. I Nflate (R. layout. custom_view, this); 7 8} 9 10} copy the code. Note that it is RelativeLayout layout = (RelativeLayout) inflater. inflate (R. layout. custom_view, this); method, the second parameter this, used to indicate that inflate is added to layout to the current object custom_view.xml. The following code is the layout file content of the custom view. Nothing special, copy code 1 as follows <? Xml version = "1.0" encoding = "UTF-8"?> 2 <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "match_parent" 4 android: layout_height = "wrap_content"> 5 6 <TextView 7 android: id = "@ + id/tvShow" 8 android: layout_width = "wrap_content" 9 android: layout_height = "wrap_content" 10 android: text = "return"/> 11 12 <TextView13 android: layout_width = "wrap_content" 14 android: layout_height = "wrap_content" 15 android: layout_alignParentRight = "true" 16 android: text = "set"/> 17 18 <RelativeLayout19 android: layout_width = "match_parent" 20 android: layout_height = "wrap_content"> 21 22 <TextView23 android: layout_width = "match_parent" 24 android: layout_height = "wrap_content" 25 android: gravity = "center_horizontal" 26 android: text = "title"/> 27 </RelativeLayout> 28 29 </RelativeLayout>

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.