DrawV
이 Android보기 (또는 확장보기) 인 경우 일반 xml 레이아웃 파일에 포함시킨 다음 setContentView(int)
과 함께 해당 레이아웃 파일을 사용할 수 있습니다.
레이아웃에서 DrawV
클래스를 참조하려면 정규화 된 이름 (패키지 포함)을 사용해야합니다.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_one"
android:text="One"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
<Button
android:id="@+id/button_two"
android:text="Two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
</LinearLayout>
<com.example.views.DrawV
android:layout_below="@id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
위의 RelativeLayout은 루트보기입니다. LinearLayout, buttons
은 두 개의 버튼을 잡고 동일한 너비로 유지하는 ViewGroup입니다 (layout_width=0dp
및 layout_weight
과 동일). DrawV
보기가 buttons
보기 아래에 배치 된 다음 상위 컨테이너의 너비와 높이 (채우기)와 일치합니다.
src/main/res/layout/activity_circles.xml
에 저장하면 활동에 setContentView(R.layout.activity_circles)
을 사용하여 레이아웃을 설정할 수 있습니다.
나는 그들 만이 작동하지 않는 것, 당신의 방법에 찬성입니다 = "match_parent"/>는 "응용 프로그램 TAP (process com.category.tap)이 예기치 않게 중지되었습니다. 다시 시도하십시오."라는 오류 메시지가 나타납니다. – user963070
@ user963070 기기에서 사용자에게 표시되는 오류입니다. 질문을 편집하고 LogCat에 표시된 스택 추적을 넣으십시오. – ataulm
안녕하세요, logcat을 추가했습니다. 그것이 약간 다른 버전의 레이아웃을위한 logcat 일지는 모르지만, 그것이 있습니다. – user963070