在Android開發中,如果我們想自定義View視圖組件,並實現在FrameLayout佈局中多個組件的同時顯示呢?
舉例來說想在自定義的View上面顯示Button 等View組件需要完成如下任務
1.在自定義View的類中覆蓋父類的構造(注意是2個參數的)
1 2 3 4 5 6 7 8 9 10 |
|
2.定義佈局文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.lovose.MyView2 android:id="@+id/View01" android:layout_width="fill_parent" android:layout_height="fill_parent" > </com.lovose.MyView2> <AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="100dip" android:layout_y="100dip"></Button> </AbsoluteLayout> </FrameLayout> |
//哈哈,你可以任意定義UI的顯示了
原文作者:sdhjob
原文鏈接:http://blog.csdn.net/sdhjob/archive/2009/12/25/5074718.aspx