嵌套片段(选项卡中的多窗格) [英] Nested Fragments (multi-pane in tab)

查看:52
本文介绍了嵌套片段(选项卡中的多窗格)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在片段中使用片段时遇到问题.第一个片段是一个选项卡视图,在一个选项卡中我想要一个像这样的多窗格布局:

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:

错误是:

android.view.InflateException:二进制 XML 文件第 8 行:错误膨胀类片段

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

标签片段(SettingsFragmentBox):

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);
        }
    }
}

xml(fragment_settings_box.xml):

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>

推荐答案

你应该阅读 http://developer.android.com/training/multiscreen/screensizes.html 来处理不同的屏幕尺寸.有一个布局包含两个片段的示例.还可以通过阅读此http://developer.android.com/training/multiscreen/adaptui.h​​tml

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

这篇关于嵌套片段(选项卡中的多窗格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆