首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓ViewFlipper -禁止在ViewFlipper内分配所有布局

安卓ViewFlipper -禁止在ViewFlipper内分配所有布局
EN

Stack Overflow用户
提问于 2014-10-11 04:26:36
回答 1查看 473关注 0票数 0

我的activity布局中有一个包含大量*.xml布局项(准确地说是108)的ViewFlipper,问题是当我启动应用程序时,ViewFlipper中的所有布局都被分配了。

有没有一种方法可以防止在启动时分配所有的ViewFlipper项目,而只在viewflipper项目加载时进行分配?

我的main_activity.xml代码

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffececec"
    tools:context=".MyActivity">

    <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <include android:id="@+id/pageMainWin"  layout="@layout/main_win" />
        // Other ViewFlipper items

    </ViewFlipper>

</RelativeLayout>
EN

回答 1

Stack Overflow用户

发布于 2014-10-11 04:51:45

尝试在布局中使用viewStub xml标签:

代码语言:javascript
复制
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

     <ViewStub
            android:inflatedId="@+id/pageMainWin"
            android:layout="@layout/main_win"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

</ViewFlipper>

然后在您的代码中,以编程方式膨胀额外的xml布局资源

代码语言:javascript
复制
ViewStub stub = (ViewStub) findViewById(R.id.pageMainWin);
View inflated = stub.inflate();

有关视图存根的更多信息,请单击此处:http://developer.android.com/reference/android/view/ViewStub.html

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

https://stackoverflow.com/questions/26307559

复制
相关文章

相似问题

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