【问题标题】:Android: Creating a custom container-viewAndroid:创建自定义容器视图
【发布时间】:2010-12-20 11:50:49
【问题描述】:

我正在尝试在 android 中创建一个自定义视图(或更好的布局),用作 2 个子视图的容器(将其视为垂直分隔 2 个容器的条形,可以上下滑动)。

我想像使用 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,但是我如何告诉我的孩子如何定位自己?

【问题讨论】:

    标签: java android layout view


    【解决方案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 中的某些方法,那么功能与该部分不同。

    【讨论】:

    • 那么我如何获得代码中定义的布局的孩子。
    猜你喜欢
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    相关资源
    最近更新 更多