一手遮天 Android - view(自定义): 通过一个自定义 ViewGroup 来演示 measure, layout, draw
一手遮天 Android - view(自定义): 通过一个自定义 ViewGroup 来演示 measure, layout, draw
示例如下:
/view/custom/CustomView2Demo.java
/**
* 参见 view/custom/CustomView2.java
* 通过一个自定义 ViewGroup 来演示 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 CustomView2Demo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_custom_customview2demo);
}
}
/layout/activity_view_custom_customview2demo.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
CustomView2 - 继承 ViewGroup 实现一个自定义的 ViewGroup(用于演示 measure, layout, draw)
-->
<com.webabcd.androiddemo.view.custom.CustomView2 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="button 1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="button 2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:text="button 3" />
</com.webabcd.androiddemo.view.custom.CustomView2>