2012-06-29 20 views
0

我寫了自己的視圖欄,它擴展了LinearLayout。我的酒吧有兩個地方用於添加按鈕或其他視圖。使我的視圖能夠接受xml中的子視圖

bar.addItemToLeft(view);bar.addItemToRight(view);

我想提出我的酒吧能接受孩子的在XML視圖中象LinearLayout:我現在使用的代碼,如項目添加到我的吧。

例如:

<com.my.ui.Bar 
    android:id="@+id/bar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

     <com.my.ui.BarLeft 
       android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

       <View/> <View/> <View/> 

     </com.my.ui.BarLeft> 

     <com.my.ui.BarRight 
       android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

       <View/> <View/> <View/> 

     </com.my.ui.BarLeft> 

</com.my.ui.Bar> 

是否possiable辦?

PS:

enter image description here

回答

1

你首先禁止左,右杆必須擴展ViewGroup中(的LinearLayout,RelativeLayout的),以便能夠Accpet頭的孩子的。

問候, Aqif哈米德

+0

我的左,右孩子的地方已經擴展的LinearLayout。 – Nik

+0

然後,您必須能夠像使用LinearLayouts一樣將控件添加到佈局中。 –

+0

請看圖像頂部。顯示地點,我想要添加項目。 – Nik

相關問題