Android の動的 UIガイドの構築の例と非常によく似た、フラグメントを使用して「動的」UI を作成しています。違いは、アクティビティではなく、フラグメント内に 2 つのフラグメントをラップしていることです。
右ペインのレイアウト大レイアウト ファイルは次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_message_multi_pane"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/some_color"
android:baselineAligned="false"
android:orientation="horizontal" >
<fragment
android:id="@+id/left_pane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:name="com.rperryng.basicfragments.leftpane"
<fragment
android:id="@+id/right_pane"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:name="com.rperryng.basicfragments.rightpane"
</LinearLayout>
左ペインの onAttach() メソッドが を呼び出そうとしますmListener = (someInterface) getParentFragment()
。ただし、レイアウトが大きなレイアウト (タブレットなど) で膨張している場合、getParentFragment()
呼び出しは null になります (if ステートメントと確認ログ メッセージで確認されます)。何を与える?これは、システムがレイアウトなどから直接インフレートするときに childFragmentManager を使用していないためですか? 代わりに実行時にフラグメントを追加する必要がありますか? サポートライブラリを使用していることに注意してください