2011-06-20 7 views
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. このカスタムビューにいくつかのボタンを追加する必要がありますが、このシナリオではどのように達成できますか。

ありがとうございます。

答えて

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

でカスタムコンポーネントでこれをやっている間、あなたが正しいコンストラクタを使用していることを確認してください。

+0

ありがとうkhotmanish、これは私のために働いた:) –