我正在尝试在 android 中创建一个自定义 View (或更好的布局),它用作 2 个 subview 的容器(将其视为垂直分隔 2 个容器的栏,可以上下滑动).
我想像 xml 中的布局一样使用它,以便您可以在其中嵌套任何 View 。 我想到了这样的事情:
<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,但我该如何告诉我的 child 如何定位自己?
最佳答案
代替
<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 中的某些方法,那么功能与那部分不同。
关于java - Android:创建自定义容器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4489337/