Android에서 맞춤 View
을 만들고 싶습니다. 나는 가능한 한 간단하게하려고 노력했으며 거의 빈 클래스 인 MyView
을 만들고 그것을 내 LinearLayout
에 사용했지만 "강제 닫기"로 시작하면 응용 프로그램이 실패합니다. 간단한 사용자 정의 View
을 어떻게 할 수 있습니까? Building Custom Components에 따르면 View
은 onMeasure()
을 덮어 쓰지 않으면 100x100 크기가됩니다.간단한 사용자 정의보기를 만드는 방법은 무엇입니까?
public class MyView extends View {
public MyView(Context context) {
super(context);
}
}
그리고 함께 LinearLayout
에 사용 : 내가 잘못
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0" />
을 뭐하는 거지?
내가 제안 itemon 생성자 및 슈퍼 클래스에 대응하는 전화를 사용하는 경우. 그런 다음 "강제 종료"가 사라졌지 만 LinearLayout
이 손상되어 MyView
이후의 구성 요소가 표시되지 않습니다. 여기
main.xml
입니다 :
public MyView(Context context, AttributeSet attrs)
는 안드로이드 프레임 워크는 위의 생성자에서 볼 수있는 UI를 구축하려고합니다 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#f00"
android:text="Hello"
/>
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#00f"
android:text="World"
/>
</LinearLayout>
여기에서 좋은 샘플을 참고하십시오. [http://www.sgoliver.net/blog/?p=1457](http://www.sgoliver.net/blog/?p=1457) –
나는 비슷합니다. 필요합니다. 당신이 필요로하는 것을 갖췄습니까? . 일부 코드 plz를 공유하십시오 – Nepster