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