메인 액티비티 클래스에서 커스텀뷰를 정의하고
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestView view= (TestView)findViewById(R.id.xml_view);
}
public class TestView extends View {
public TestView(Context context) {
super(context);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint paint = new Paint();
canvas.drawColor(Color.RED);
paint.setColor(Color.BLUE);
canvas.drawCircle(100,100,500,paint);
}
}
}
아래와 같이 메인 xml에 커스텀 뷰를 작성했는데
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.study.high5light.myquestion.MainActivity">
<View
android:class = "com.study.high5light.myquestion.MainActivity.TestView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/xml_view"/>
</android.support.constraint.ConstraintLayout>
findbyviewid로 객체를 얻으려고 하변 빌드 에러가 납니다
왜 그런가요????
알려주시면 감사하겠습니다