1

私は Android 開発に不慣れで、カスタム ビューとビューのカスタマイズに xml を使用することについて質問があります。

だから私のコードでは、拡張ビュークラスを使用してビューを定義しています。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Display display = getWindowManager().getDefaultDisplay();
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);        
    draw = new DrawView(this, display.getWidth(), display.getHeight(), vibrator);
    setContentView(draw);//custom view called DrawView
}   

そして、DrawView クラスでは、キャンバスを使用して操作を実行しています。

私の質問は、

  1. 定義したこのビューと組み合わせて XML レイアウトを使用できますか?

  2. このカスタム ビューにいくつかのボタンを追加する必要があります。このシナリオでそれを実現するにはどうすればよいですか。

ありがとうございました。

4

1 に答える 1

3

レイアウト内にカスタム ビューを埋め込むことができます。次に例を示します。

<?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="horizontal" android:background="#FFFFFF">
    <ListView android:id="@+id/channelsLogos" android:scrollbars="none"
        android:layout_height="fill_parent" android:layout_weight=".20"
        android:layout_width="100dip">
    </ListView>
    <test.poc.CustomScrollView
        android:id="@+id/scrollViewVertical" android:scrollbars="none"
        android:layout_weight=".80" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </test.poc.CustomScrollView>

</LinearLayout>

CustomScrollView はパッケージ test.poc のカスタムコンポーネントです

これを行うときは、正しいコンストラクターを使用していることを確認してください。

于 2011-06-20T16:46:09.613 に答える