Nested Fragments (multi-pane in tab)

喜夏-厌秋 提交于 2019-12-12 04:38:13

问题


i have problems to use a fragment in a fragment. The first fragment is a tab view an in one tab i want to have a multi-pane Layout like this:

The error is:

android.view.InflateException: Binary XML file line #8: Error inflating class fragment

The tab fragment (SettingsFragmentBox):

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class SettingsFragmentBox extends Fragment implements SettingsFragmentBoxList.OnItemSelectedListener{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_settings_box, container, false);
        return rootView;
    }

    public void onBoxSelect(int id) {
        SettingsFragmentBoxDetail fragment = (SettingsFragmentBoxDetail) getFragmentManager().findFragmentById(R.id.box_detail);
        if (fragment != null && fragment.isInLayout()) {
            fragment.setText(id);
        } else {
            Intent intent = new Intent(getActivity(),SettingsActivityBoxDetail.class);
            intent.putExtra(SettingsActivityBoxDetail.EXTRA_ID, id);
            startActivity(intent);
        }
    }
}

The xml (fragment_settings_box.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/box_list"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        class="de.resper.e2cast.SettingsFragmentBoxList"
        tools:layout="@layout/fragment_settings_box_list">
    </fragment>

    <fragment
        android:id="@+id/box_detail"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        class="de.resper.e2cast.SettingsFragmentBoxDetail"
        tools:layout="@layout/fragment_settings_box_detail">
    </fragment>

</LinearLayout>

回答1:


Usually this is done using fragments in ACTIVITIES, not in other fragments. Are you sure you really want fragments in other fragments ?

The picture you are referring to is by the way showing this scenario (ACTIVITIES contain fragment A or B).




回答2:


You should read http://developer.android.com/training/multiscreen/screensizes.html to handle different screensizes. There is an example with a layout containt two fragments in it. Also learn how to adapt to it by reading this http://developer.android.com/training/multiscreen/adaptui.html



来源:https://stackoverflow.com/questions/25981286/nested-fragments-multi-pane-in-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!