Android カスタムViewを作成する際は、下記コンストラクタを記述すること
AttributeSet attrsが必要
MyView.java
public class MyView extends View {
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
}
}
activity_main.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="match_parent">
<com.test.android.viewtest.MyView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>