布局

引入布局

在xml文件中直接引入布局
<include layout="@layout/title"/>
<?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="@mipmap/ic_launcher">
    <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="@mipmap/ic_launcher"
        android:text="Back"
        android:textColor="#000000"
        />
    <TextView
        android:layout_width="0dp"
        android:gravity="center"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:text="TileText"
        android:textColor="#000000"
        android:layout_height="wrap_content"
        android:textSize="24sp"/>
    <Button
        android:id="@+id/title_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@mipmap/ic_launcher"
        android:text="Edit"
        android:textColor="#000000"
        />
</LinearLayout>

自定义控件

#直接自定义一个类
public class TileLayout extends LinearLayout {
    public TileLayout(Context context, AttributeSet attrs) {
        super(context,attrs);
        LayoutInflater.from(context).inflate(R.layout.title,this);
    }
}
#在xml文件中调用
<text.testview.TileLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></text.testview.TileLayout>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容