【发布时间】:2014-06-17 16:15:05
【问题描述】:
我们正在将加载对话框作为片段添加为容器中的临时视图,以在显示主视图之前处理来自服务器的数据时向用户显示。我们希望能够在诸如框架布局之类的面板中显示此对话框,因为我们使用的特定视图是一个自定义容器片段,用于模拟 iOS SplitViewController。潜在地,当加载到平板电脑上时,可能会有 2 个加载片段同时显示在它们各自的容器中。
我们使用的片段继承自 DialogFragment,所有其他片段基本上都是高度定制的列表片段。
我们面临的问题是,当我们直接使用 Fragment 的 childFragmentManager.Replace() 方法将临时 Fragment 添加到容器中时,它完全弄乱了后退导航。当它被用作调用 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>
任何帮助将不胜感激!
【问题讨论】:
标签: android android-fragments android-dialogfragment