2
<com.test.www.BrushPreview android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

そしてこれはそうではありません:

<View class="com.test.www.BrushPreview" android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

ドキュメントhttp://developer.android.com/guide/topics/ui/custom-components.html#modifyingに従うと、両方の方法で機能するはずです。私は何が間違っているのですか?

編集:小文字のビューは機能しているようです!もうやってみたと思った…ありがとう!さらに、ビュークラスでこのコンストラクターを使用することは非常に重要です。

public BrushPreview(Context context, AttributeSet attrs) 

そうしないと、呼び出されません。

4

1 に答える 1

2

viewカスタムレイアウトのxmlでは小文字を使用する必要があります。

<view class="com.test.www.BrushPreview" android:id="@+id/brushview"
    android:layout_width="100dip" android:layout_height="100dip"
    android:layout_gravity="center" />

あなたのリンクによると)、そしてそれはうまくいくはずです。

android.view.Viewそれ以外の場合は、インスタンスを作成しようとします。

于 2011-05-10T07:40:49.433 に答える