Android 如何管理方向更改的两个片段?

Android 如何管理方向更改的两个片段?,android,android-fragments,Android,Android Fragments,我有一个活动che包含一个片段,我称之为片段a。 当屏幕足够大时,(大布局)A显示另外两个片段,B(A产品列表)和C(列表中所选项目的详细信息)。 当屏幕不够大时,A只显示片段B,当我单击某个列表项时,它打开带有所选产品的片段C 问题是,在纵向模式下,片段C是可见的(片段的详细信息),如果我改变方向,它将返回可见片段B(列表),但我希望在横向模式下,片段C是可见的 我怎样才能做到这一点 下面是一些代码: 大屏幕 <?xml version="1.0" encoding="utf-8

我有一个活动che包含一个片段,我称之为片段a。 当屏幕足够大时,(大布局)A显示另外两个片段,B(A产品列表)和C(列表中所选项目的详细信息)。 当屏幕不够大时,A只显示片段B,当我单击某个列表项时,它打开带有所选产品的片段C

问题是,在纵向模式下,片段C是可见的(片段的详细信息),如果我改变方向,它将返回可见片段B(列表),但我希望在横向模式下,片段C是可见的

我怎样才能做到这一点

下面是一些代码:

大屏幕

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/book_list_content"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <FrameLayout
        android:id="@+id/book_details_content"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"/>

</LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/book_list_content"
        android:layout_below="@id/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>


</LinearLayout>
在你的碎片里

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        frameLayout = new FrameLayout(getActivity());
        rootView = inflater.inflate(R.layout.fragment_home_page_updated, null);
        frameLayout.addView(rootView);
        initUI();

        return frameLayout;
    }
并进行OnConfiguration更改()


它的行为方式是相同的,也许我必须在initUI中放入一些特定的内容?在initUI()中,初始化所有的TextView、按钮和所有。
 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        frameLayout = new FrameLayout(getActivity());
        rootView = inflater.inflate(R.layout.fragment_home_page_updated, null);
        frameLayout.addView(rootView);
        initUI();

        return frameLayout;
    }
@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setRetainInstance(true);
        frameLayout.removeAllViews();
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.fragment_home_page_updated, null);
        frameLayout.addView(rootView);
        initUI();
    }