开发者社区> 问答> 正文

安卓关于Fragment的问题activity启动出错

MainActivity.java没动

 public class LeftFragment extends Fragment {
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
 Bundle savedInstanceState) {
 View view = inflater.inflate(R.layout.left_fragment, container, false);
 return view;
 }
 }
 left_fragment.xml:
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 android:id="@+id/button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center_horizontal"
 android:text="Button"
 />

 public class RightFragment extends Fragment {
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
 Bundle savedInstanceState) {
 View view = inflater.inflate(R.layout.right_fragment, container, false);
 return view;
 }
 }
 right_fragment.xml:
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#00ff00"
 android:orientation="vertical" >
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center_horizontal"
 android:textSize="20sp"
 android:text="This is right fragment"
 />

 activity_main.xml:
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

android:id="@+id/left_fragment"
 android:name="com.example.fragmenttest.LeftFragment"
 android:layout_width="0dp"
 android:layout_height="match_parent"
 android:layout_weight="1" />
 android:id="@+id/right_fragment"
 android:name="com.example.fragmenttest.RightFragment"
 android:layout_width="0dp"
 android:layout_height="match_parent"
 android:layout_weight="1" />

展开
收起
爵霸 2016-03-25 09:11:34 2144 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载