小屁嗨 2016-03-24 10:40
浏览 1372
已结题

fragment+viewpage中fragment的替换问题

在我hide的时候再add一个fragment的时候不会显示界面,如果我用replace方法的时候是显示替换后的界面。追加问:在我replace替换后的fragment中又有一个Viewpage+fragment,再我返回的时候怎么释放掉后面这个viewpage中的Fragment

private CategoryFragment categoryFragment;

FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
categoryFragment = CategoryFragment.newInstance( categorySummaryList,bundle.get("name").toString());
fragmentTransaction.hide(DouniwanFragment.this);//DouniwanFragment这个是当前放在viewpage中的一个fragment
fragmentTransaction.add(R.id.comment_viewpage_content, categoryFragment, "gridViewFragment");
// fragmentTransaction.replace(R.id.comment_viewpage_content, categoryFragment, "gridViewFragment");
fragmentTransaction.addToBackStack("DnwFragmentToCategoryFragment");
fragmentTransaction.commit();

下面是xml替换的文件

android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/comment_viewpage_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dnw_main"
android:orientation="vertical">
android:layout_height="50dp"
android:background="#fff"
android:orientation="horizontal">
<!--android:onClick="toggleMenu"-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/set"
/>
android:id="@+id/dnw_search"
android:hint="搜索动漫、作者"
android:textColorHint="#5000"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="35dp"
android:layout_gravity="center"
android:drawableLeft="@mipmap/search"
android:background="@drawable/textview_search"
android:drawablePadding="10dp"
/>
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/icon_me"/>

<android.support.v4.widget.SwipeRefreshLayout

        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    <ListView
        android:id="@+id/dnw_main_lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:headerDividersEnabled="false"/>
    </android.support.v4.widget.SwipeRefreshLayout>

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建