【发布时间】:2014-10-11 04:51:45
【问题描述】:
我的活动布局中有一个带有很多 *.xml 布局项(准确地说是 108 个)的 ViewFlipper,问题是当我启动应用程序时,ViewFlipper 中的所有布局都已分配。
有没有办法防止在启动时分配所有 ViewFlipper 项目,并使其仅在加载 viewFlipper 项目时分配?
我的 main_activity.xml 代码
<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>
【问题讨论】:
-
为什么会有108个布局项?
-
您基本上可以在不使用时将主布局项设置为
layout.setVisiblity(View.GONE),然后在您确实需要时再次提供View.VISIBLE。在需要之前,这不会消耗资源。例如当您向左或向右平移时。
标签: android android-layout viewflipper