首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:创建自定义容器-view

Android:创建自定义容器-view
EN

Stack Overflow用户
提问于 2010-12-20 19:50:49
回答 1查看 6.2K关注 0票数 3

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

我想像使用xml中的布局一样使用它,这样您就可以在其中嵌套任何视图。我想到了一些类似的东西:

代码语言:javascript
复制
            <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自动取款机,但我如何告诉我的孩子如何定位自己?

EN

回答 1

Stack Overflow用户

发布于 2010-12-20 20:16:08

而不是

代码语言:javascript
复制
<view class="at.calista.quatscha.views.SwipebarLayout"
        android:id="@+id/sbl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

您可以使用

代码语言:javascript
复制
<at.calista.quatscha.views.SwipebarLayout
        android:id="@+id/sbl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

如果您的SwipebarLayout类扩展了LinearLayout,那么它的行为将与您在代码中使用LinearLayout标记的方式完全相同,并且您可以使用与LinearLayout完全相同的方式来定位子类。当然,如果您已经覆盖了LinearLayout中的某些方法,那么其功能将与该部分不同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4489337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档