2010-12-20 32 views
3

我想在android中創建一個自定義視圖(或更好的佈局),作爲2個子視圖的容器(將其視爲一個將2個容器垂直分隔的條,可以上下滑動)。Android:創建一個自定義的容器視圖

我想將它用作xml中的佈局,以便您可以在其中嵌套任何視圖。 我想到了這樣的事情:

  <view class="at.calista.quatscha.views.SwipebarLayout" 
      android:id="@+id/sbl" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <!-- Top View --> 
      <Button android:text="Top" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 

      <!-- Bottom View --> 
      <Button android:text="Bottom" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</view> 

這個XML應該給我兩個按鍵之間的滑動式酒吧。

但是,我不知道如何實現這一點,我正在擴展LinearLayout atm,但我該如何告訴我的孩子如何定位自己?的

回答

1

代替

<view class="at.calista.quatscha.views.SwipebarLayout" 
     android:id="@+id/sbl" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

可以使用

<at.calista.quatscha.views.SwipebarLayout 
     android:id="@+id/sbl" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

如果您SwipebarLayout類擴展的LinearLayout它的行爲完全一樣,如果你會的LinearLayout標籤在你的代碼,而不是你可以定位孩子們和LinearLayout完全一樣。當然,如果你已經重寫了LinearLayout的一些方法,那麼它的功能就不同於那個部分。

+2

那麼,我如何得到在代碼中定義的佈局的孩子。 – AndroidDev 2012-09-27 13:44:59