首先创建左右两个碎片的布局,然后对应布局分别写两个继承于Fragment的类,重写类中的onViewCreate方法
在重写方法内获得碎片布局的View。
最后在main布局中添加两个fragment控件,注意每个控件要添加android:name="[里面是对应的碎片类]"。
left
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Administrator on 2017/11/20.
*/
public class LeftFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
View view=inflater.inflate(R.layout.activity_leftfragment,container,false);
return view;
}
}
right
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Administrator on 2017/11/20.
*/
public class RightFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState){
View view=inflater.inflat