0
私はフラグメントにAフラグメントと呼ばれるフラグメントが含まれています。 画面が十分に大きければ(レイアウトが大きい)、他の2つのフラグメント、B(製品のリスト)、C選択された項目のリストから)。 画面のサイズが十分でない場合、AはフラグメントBのみを表示し、いくつかのリストアイテムをクリックすると、選択した製品でフラグメントCが開きます。オリエンテーションの変更で2つの断片を管理するにはどうすればいいですか?
問題は、ポートレートモードでフラグメントCが表示されている(フラグメントvithの詳細)、私が方向を変更した場合、フラグメント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>
そして最後に、フラグメントA:
public class HomeFragment extends Fragment implements ListFragment.onBookSelectedListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedIstance){
return inflater.inflate(R.layout.drawer_fragments,container,false);
/*drawer_fragments is the name of the layout that i've posted above*/
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
if(savedInstanceState == null) {
ListFragment listfrag = new ListFragment();
FragmentManager fragManager = getChildFragmentManager();
fragManager.beginTransaction().replace(R.id.book_list_content, listfrag).commit();
if (view.findViewById(R.id.book_details_content) != null) {
/*Here if the screen is large enought to see also the details*/
fragManager.beginTransaction().replace(R.id.book_details_content, new DetailsFragment()).commit();
}
}
/*Other code...*/
}
は、
それはたぶん私はinitUI内の特定の何かを配置する必要があり、同じように動作しますか? initUI()内の – Ollaw
は、すべてのTextView、Buttonおよびallを初期化します。 – Shekhar