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>