转载请注明出处amoscxy的博客:https://mp.csdn.net/mdeditor/80151114
自定义控件之 - 自定义LinearLayout控件
1.1 引入布局include
- 最终效果
要创建这样的标题栏只需在界面中加入,两个Button和一个TextView,然后布局中摆放好就可以了,可这样却存在着一个问题,一般我们的程序中有可能有很多activity都需要这样的标题栏,如果在每个activity的布局中都编写一遍同样的标题栏代码,明显就会导致大量的代码重复,这个时候我们就可以使用引入布局的方式来解决这个问题
实例目录
title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_bg">
<Button
android:id="@+id/title_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:background="@drawable/back_bg"
android:text="Back"
android:textColor="#fff" />
<