使用嵌套碎片的Android备份/备份导航



我们正在添加一个加载对话框作为一个片段,作为容器内的临时视图,以显示用户,而来自服务器的数据在显示主视图之前被处理。我们希望能够在面板(如框架布局)中显示此对话框,因为我们正在使用的特定视图是一个自定义容器片段来模拟iOS SplitViewController。当加载到平板电脑上时,可能会有两个加载片段同时显示在各自的容器中。

我们正在使用的片段继承自DialogFragment,所有其他片段基本上都是高度定制的列表片段。

我们面临的问题是,当我们直接使用fragment的childFragmentManager.Replace()方法将临时片段添加到容器中时,它完全搞乱了返回导航。当它被用作调用dialog.show()的模态对话框时,返回导航是好的,但是对话框不会显示在我们想要它显示的框架中。

是否有一种方法可以a.)修复后导航问题或b.)在调用dialog. show()时使对话框显示在指定的框架中?

下面是对话片段的代码:
public class TestLoadingFragment : DialogFragment
{
    public override void OnCreate (Bundle savedInstanceState)
    {
        base.OnCreate (savedInstanceState);
        this.Cancelable = false;
        this.HasOptionsMenu = false;
        this.SetStyle(StyleNoTitle, 0);
    }
    public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.Inflate(Resource.Layout.TestLoadingFragment_Layout, container, false);
    }

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:minWidth="200dip" android:minHeight="200dip"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/loadingViewProgress" android:layout_centerInParent="true" /> <TextView android:text="Loading Please Wait" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/lblViewLoadingText" android:gravity="center" android:layout_below="@+id/loadingViewProgress" android:textColor="#ff000000" /> </RelativeLayout> </LinearLayout>

任何帮助将非常感激!

如果您正在使用ListFragment,您可以调用setListShown(false)来显示加载进度指示器,同时加载数据,当listview准备好时调用setListShown(true)

或者如果你想要一个自定义的旋转器布局视图,你可以在<FrameLayout>中声明一个<ListView>项和一个<LinearLayout>项:

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ListView
        android:id="@+id/listview"
        android:visibility="gone"
        android:fadingEdgeLength="0dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <LinearLayout 
        android:id="@+id/spinner"
        android:visibility="visible" 
        android:orientation="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:minWidth="200dip" 
        android:minHeight="200dip"> 
        <RelativeLayout 
            android:layout_width="match_parent" 
            android:layout_height="match_parent"> 
            <ProgressBar 
                style="?android:attr/progressBarStyleLarge" 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:id="@+id/loadingViewProgress" 
                android:layout_centerInParent="true" /> 
             <TextView 
                android:text="Loading Please Wait" 
                android:textAppearance="?android:attr/textAppearanceMedium" 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:id="@+id/lblViewLoadingText" 
                android:gravity="center" 
                android:layout_below="@+id/loadingViewProgress" 
                android:textColor="#ff000000" /> 
        </RelativeLayout> 
    </LinearLayout>
</FrameLayout>

并设置一次只显示一个视图:

ListView list = (ListView)findViewById(R.id.listview);
LinearLayout spinner = (LinearLayout)findViewById(R.id.spinner);

加载数据时:

spinner.setVisibility(View.VISIBLE);
list.setVisibility(View.GONE);

当数据准备好时:

spinner.setVisibility(View.GONE);
list.setVisibility(View.VISIBLE);

最新更新