2010-12-20 97 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