目录
1 android自定义view (UI组件)
1.1 自定义view的简介
1.1.1 android自定义view几种方式
自定义
View
的实现方式有以下几种:
组合控件,继承控件,自绘控件。
详细可分为:
自定义组合控件,继承系统
View
控件,继承系统
ViewGroup
,自绘
View
控件,自绘
ViewGroup
控件。
1.2 自定义组合控件
组合控件就是将多个控件组合成一个新的控件,可以重复使用。
应用场景:在项目中经常会遇到一些比较复杂的
UI
块需要用在
多处使用
,那么我们就可以通过五大布局
和基本控件组合成一个新的布局
View
,这样就可以方便的将该
UI
用在项目的不同页面中,比如一个标题
栏。这种方式比较简单,只要通过布局文件实现相应的
UI
,然后将该
UI
加到适合的五大布局中即可。
1.2.1 自定义组合控件的使用步骤
1.
编写布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#FA88AF"
android:id="@+id/head">
<ImageView
android:id="@+id/iv_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
app:srcCompat="@drawable/ic_baseline_arrow_back_24" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height=