Android:创建自定义容器视图

3
我想创建一个自定义视图(或更好的是布局),在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,但是我该怎么告诉我的子视图们该如何定位自己呢?

1个回答

0

替代

<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的某些方法,则该部分的功能将有所不同。

3
那么我该如何获取代码中定义的布局的子项呢? - AndroidDev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接