我的activity布局中有一个包含大量*.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>发布于 2014-10-11 04:51:45
尝试在布局中使用viewStub xml标签:
<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布局资源
ViewStub stub = (ViewStub) findViewById(R.id.pageMainWin);
View inflated = stub.inflate();有关视图存根的更多信息,请单击此处:http://developer.android.com/reference/android/view/ViewStub.html
https://stackoverflow.com/questions/26307559
复制相似问题