我正在尝试嵌套片段,因为我的xml布局开始难以维护。嵌套片段 - 从片段开始的片段不会膨胀布局xml
从片段我点击跳过按钮时开始一个片段。我尝试了一个正常的开始和一个孩子的片段。在这两种情况下,我进入膨胀方法的片段,但我的屏幕保持空白。当然,当我将片段称为第一层时,布局正确膨胀。
呼叫转移到第二个片段一日一中:
skip.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
SelectServiceFragment ssf = new SelectServiceFragment();
ft.add(ssf,"SelectService");
ft.commit();
}
});
SelectServiceFragment:
public class SelectServiceFragment extends Fragment {
Context context;
public SelectServiceFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootview = null;
rootview = inflater.inflate(R.layout.select_svce_fragment, container, false);
return rootview;
}
和我的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Select service!!!!"
android:textColor="#000000"
/>
</RelativeLayout>
我错过了在嵌套片段的东西吗?
你使用过chindfragment manager吗? –
我尝试了两种方法。 FragmentTransaction ft = getChildFragmentManager()。beginTransaction(); ft.replace(R.id.selsvcefrag,ssf);我试过非孩子的方法,因为我想消除framelayout(R.id.selsvcefrag)。这两种方式导致膨胀显示一个空的屏幕。 – narb