2014-09-22 63 views
0

我在使用片段中的片段时遇到问题。第一个片段是一个标签在一个选项卡查看我想有一个多窗格布局是这样的:嵌套片段(选项卡中的多窗格)

enter image description here

错误是:

android.view.InflateException:二进制XML文件行#8:错误 充气类片段

的标签片段(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):

<?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> 

回答

0

通常,这是在活动使用的片段,而不是在其它片段完成的。你确定你真的想要碎片在其他片段?

您所指的图片是通过展示此场景的方式(活动包含片段A或B)。

+0

我喜欢本教程中的Tab Layout:http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views- 1 /现在想要在一个Tab中有一个像本教程中的片段视图:http://www.vogella.com/tutorials/AndroidFragments/article.html – Laire 2014-09-22 19:27:29

0

您应该阅读http://developer.android.com/training/multiscreen/screensizes.html来处理不同的屏幕尺寸。有一个布局包含两个片段的例子。还要学习如何通过阅读以适应它http://developer.android.com/training/multiscreen/adaptui.html

+0

我的选项卡和多平面视图的例子都适用于他们自己。但现在我有一个问题来结合他们。 – Laire 2014-09-22 19:58:00