一手遮天 Android - view(自定义): 通过一个自定义 View 来演示 measure, layout, draw
示例如下:
/view/custom/CustomView1Demo.java
/**
* 参见 view/custom/CustomView1.java
* 通过一个自定义 View 来演示 measure, layout, draw
*/
package com.webabcd.androiddemo.view.custom;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.webabcd.androiddemo.R;
public class CustomView1Demo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_custom_customview1demo);
}
}
/layout/activity_view_custom_customview1demo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical">
<!--
CustomView1 - 继承 View 实现一个自定义的 View(用于演示 measure, layout, draw)
-->
<com.webabcd.androiddemo.view.custom.CustomView1
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:titleBackgroundColor="@color/red"
app:titleColor="@color/white"
app:titleSize="24dp"
app:titleText="text" />
<com.webabcd.androiddemo.view.custom.CustomView1
android:layout_width="100dp"
android:layout_height="100dp"
app:titleBackgroundColor="@color/red"
app:titleColor="@color/white"
app:titleSize="24dp"
app:titleText="text" />
<com.webabcd.androiddemo.view.custom.CustomView1
android:layout_width="match_parent"
android:layout_height="match_parent"
app:titleBackgroundColor="@color/blue"
app:titleColor="@color/white"
app:titleSize="24dp"
app:titleText="text" />
</LinearLayout>