一、静态页面
二、整体页面
三、页面实现的步骤:
1.上部分RecyclerView的实现:
1.1实现主布局,创建item_list_lesson.xml布局文件,上部分用recyclerview实现,下部分用分段实现

1.2创建recyclerview_lesson.xml布局文件,实现recyclerview的内容部分样式

1.3创建LessonDataBean文件,封装数据

1.4创建LessonAdapter适配器文件,实现数据传输

1.5在主活动LessonListActivity中,加入数据,实现静态布局

2.下部分片段嵌套Recyclerview的实现:
2.1创建activity_lesson_fragment_one.xml一个片段recyclerview的页面

2.2创建item_lesson_fragment.xml页面布局内容
2.3创建layout_base.xml布局文件,将容器放入
2.4创建ListDataBean文件,将数据封装
2.5创建ListAdapter适配器文件,传输数据
2.6创建BaseFragment文件,将容器放入,BaseFragment(子片段)继承Fragment(片段)
2.7创建LessonFragmentOne文件,LessonFragmentOne继承BaseFragment
2.8添加剩下三个页面

3.下部分片段点击切换的实现:
3.1在LessonListActivity文件中判断,进行片段隐藏
3.2在LessonListActivity文件中添加管理器,进行判断,点击则显示该页面
3.3在LessonAdapter文件中添加按钮,获取按钮的位置
3.4在LessonAdapter文件中添加点击事件,实现点击效果
四、整体代码
1.item_list_lesson.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".LessonListActivity"android:orientation="vertical"android:background="#fff6f6f6"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_project"android:layout_width="match_parent"android:layout_height="50dp"android:paddingTop="20dp"/><FrameLayoutandroid:id="@+id/fra_project"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:paddingTop="20dp"android:paddingLeft="60dp"/></LinearLayout>
2.recyclerview_lesson.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="36dp"android:orientation="horizontal"android:gravity="center"android:paddingLeft="60dp"><TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="党员支部大会"android:textSize="12sp"android:textColor="#73000000"/></LinearLayout>
3.LessonDataBean文件代码
package com.example.fragmentproject.bean;public class LessonDataBean {private int title;public LessonDataBean(int title) {this.title = title;}public int getTitle() {return title;}public void setTitle(int title) {this.title = title;}}
4.LessonAdapter文件代码
package com.example.fragmentproject.adapter;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;import androidx.annotation.NonNull;import androidx.recyclerview.widget.RecyclerView;import com.example.fragmentproject.R;import com.example.fragmentproject.bean.LessonDataBean;import java.util.List;public class LessonAdapter extends RecyclerView.Adapter<LessonAdapter.MyViewHolder>{private Context context;private List<LessonDataBean> list;private View inflate;public LessonAdapter(Context context, List<LessonDataBean> list) {this.context = context;this.list = list;}//第一步,定义一个接口public interface OnItemClickListener{void onClick(int position);}private OnItemClickListener listener;//第二步,写一个公共的方法public void setOnItemClickListener(OnItemClickListener listener){this.listener=listener;}@NonNull@Overridepublic MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {inflate= LayoutInflater.from(context).inflate(R.layout.recyclerview_lesson,parent,false);MyViewHolder viewHolder=new MyViewHolder(inflate);return viewHolder;}@Overridepublic void onBindViewHolder(@NonNull MyViewHolder holder, int position) {holder.tv_title.setText(list.get(position).getTitle());holder.itemView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (listener!=null){listener.onClick(position);}}});}@Overridepublic int getItemCount() {return list.size();}class MyViewHolder extends RecyclerView.ViewHolder{private TextView tv_title;public MyViewHolder(@NonNull View itemView) {super(itemView);tv_title=itemView.findViewById(R.id.tv_title);}}}
5.LessonListActivity文件代码
package com.example.fragmentproject;import androidx.appcompat.app.AppCompatActivity;import androidx.fragment.app.FragmentManager;import androidx.fragment.app.FragmentTransaction;import androidx.recyclerview.widget.DefaultItemAnimator;import androidx.recyclerview.widget.DividerItemDecoration;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.RecyclerView;import android.content.Context;import android.os.Bundle;import android.text.BoringLayout;import android.widget.FrameLayout;import com.example.fragmentproject.adapter.LessonAdapter;import com.example.fragmentproject.adapter.ListAdapter;import com.example.fragmentproject.bean.LessonDataBean;import com.example.fragmentproject.bean.ListDataBean;import com.example.fragmentproject.fragment.LessonFragmentFour;import com.example.fragmentproject.fragment.LessonFragmentOne;import com.example.fragmentproject.fragment.LessonFragmentThree;import com.example.fragmentproject.fragment.LessonFragmentTwo;import java.util.ArrayList;public class LessonListActivity extends AppCompatActivity {private RecyclerView recyclerView;private LessonAdapter lessonAdapter;private ArrayList<LessonDataBean> list=new ArrayList<>();private Context context;private int[] title={R.string.title_one,R.string.title_two,R.string.title_three,R.string.title_four};private LessonFragmentOne lessonFragmentOne;private LessonFragmentTwo lessonFragmentTwo;private LessonFragmentThree lessonFragmentThree;private LessonFragmentFour lessonFragmentFour;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.item_list_lesson);context=this;initData();initView();setFragment(0);}private void initData(){for (int i=0;i<4;i++){LessonDataBean lessonDataBean=new LessonDataBean(title[i]);list.add(lessonDataBean);}}private void initView(){recyclerView=findViewById(R.id.rv_project);lessonAdapter=new LessonAdapter(context,list);lessonAdapter.setOnItemClickListener(new LessonAdapter.OnItemClickListener() {@Overridepublic void onClick(int position) {setFragment(position);}});LinearLayoutManager manager=new LinearLayoutManager(context);manager.setOrientation(LinearLayoutManager.HORIZONTAL);recyclerView.setLayoutManager(manager);recyclerView.setItemAnimator(new DefaultItemAnimator());recyclerView.setAdapter(lessonAdapter);setFragment(0);}private void hideFragments(FragmentTransaction transaction){if (lessonFragmentOne!=null){transaction.hide(lessonFragmentOne);}if (lessonFragmentTwo!=null){transaction.hide(lessonFragmentTwo);}if (lessonFragmentThree!=null){transaction.hide(lessonFragmentThree);}if (lessonFragmentFour!=null){transaction.hide(lessonFragmentFour);}}public void setFragment(int position){//获取Fragment管理器FragmentManager fragmentManager=getSupportFragmentManager();//开启事务FragmentTransaction transaction=fragmentManager.beginTransaction();//隐藏所有FragmenthideFragments(transaction);switch (position) {default:break;case 0://显示对应Fragmentif (lessonFragmentOne == null) {lessonFragmentOne = new LessonFragmentOne();transaction.add(R.id.fra_project, lessonFragmentOne, "lessonFragmentOne");} else {transaction.show(lessonFragmentOne);}break;case 1:if (lessonFragmentTwo == null) {lessonFragmentTwo = new LessonFragmentTwo();transaction.add(R.id.fra_project, lessonFragmentTwo, "lessonFragmentTwo");} else {transaction.show(lessonFragmentTwo);}break;case 2:if (lessonFragmentThree==null){lessonFragmentThree=new LessonFragmentThree();transaction.add(R.id.fra_project,lessonFragmentThree,"lessonFragmentThree");}else {transaction.show(lessonFragmentThree);}break;case 3:if (lessonFragmentFour == null) {lessonFragmentFour=new LessonFragmentFour();transaction.add(R.id.fra_project,lessonFragmentFour,"lessonFragmentFour");}else {transaction.show(lessonFragmentFour);}break;}//提交事务transaction.commitAllowingStateLoss();}}
6.activity_lesson_fragment_one.xml布局文件
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".fragment.LessonFragmentOne"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_fra_one"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>
7.item_lesson_fragment.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="400dp"android:layout_height="71dp"android:orientation="vertical"android:background="@drawable/fra_radius_border"android:padding="12dp"android:layout_marginBottom="20dp"><TextViewandroid:id="@+id/tv_headline"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府"android:textSize="14sp"android:textColor="#d9000000"android:lines="1"android:ellipsize="end"/><TextViewandroid:id="@+id/tv_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="2020-12-17 09:00"android:textSize="10sp"android:textColor="#73000000"android:layout_gravity="end"android:layout_marginTop="12dp"/></LinearLayout>
8.layout_base.xml布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><FrameLayoutandroid:id="@+id/fl_content"android:layout_width="match_parent"android:layout_height="match_parent" ></FrameLayout></LinearLayout>
9.ListDataBean文件代码
package com.example.fragmentproject.bean;public class ListDataBean {private String headline;private String time;public ListDataBean(String headline, String time) {this.headline = headline;this.time = time;}public String getHeadline() {return headline;}public void setHeadline(String headline) {this.headline = headline;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}}
10.ListAdapter文件代码
package com.example.fragmentproject.adapter;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;import androidx.annotation.NonNull;import androidx.recyclerview.widget.RecyclerView;import com.example.fragmentproject.R;import com.example.fragmentproject.bean.ListDataBean;import java.util.List;public class ListAdapter extends RecyclerView.Adapter<ListAdapter.MyViewHolder>{private Context context;private List<ListDataBean> list;private View inflate;public ListAdapter(Context context, List<ListDataBean> list) {this.context = context;this.list = list;}@NonNull@Overridepublic MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {inflate= LayoutInflater.from(context).inflate(R.layout.item_lesson_fragment,parent,false);MyViewHolder viewHolder=new MyViewHolder(inflate);return viewHolder;}@Overridepublic void onBindViewHolder(@NonNull MyViewHolder holder, int position) {holder.tv_headline.setText(list.get(position).getHeadline());holder.tv_time.setText(list.get(position).getTime());}@Overridepublic int getItemCount() {return list.size();}class MyViewHolder extends RecyclerView.ViewHolder{private TextView tv_headline;private TextView tv_time;public MyViewHolder(@NonNull View itemView) {super(itemView);tv_headline=itemView.findViewById(R.id.tv_headline);tv_time=itemView.findViewById(R.id.tv_time);}}}
11.BaseFragment件代码
package com.example.fragmentproject.base;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.fragment.app.Fragment;import com.example.fragmentproject.R;public abstract class BaseFragment extends Fragment {protected Context context;public View rootView;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);context = getActivity();}@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater,@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {rootView = inflater.inflate(R.layout.layout_base, container, false);((ViewGroup) rootView.findViewById(R.id.fl_content)).addView(getLayoutInflater().inflate(getLayoutId(), null));return rootView;}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);initView();}/*** 返回页面layout** @return layout*/protected abstract int getLayoutId();/*** 初始化View*/protected abstract void initView();}
12.LessonFragmentOne文件代码
package com.example.fragmentproject.fragment;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity;import androidx.fragment.app.Fragment;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.RecyclerView;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.FrameLayout;import com.example.fragmentproject.LessonListActivity;import com.example.fragmentproject.R;import com.example.fragmentproject.adapter.ListAdapter;import com.example.fragmentproject.base.BaseFragment;import com.example.fragmentproject.bean.ListDataBean;import java.util.ArrayList;public class LessonFragmentOne extends BaseFragment {private RecyclerView mRecyclerView;private ListAdapter listAdapter;private ArrayList<ListDataBean> arrayList=new ArrayList<>();private String[] headline={"国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府"};private String[] time={"2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00"};@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);}@Overrideprotected int getLayoutId(){return R.layout.activity_lesson_fragment_one;}@Overrideprotected void initView(){for (int i=0;i<10;i++){ListDataBean listDataBean=new ListDataBean(headline[i],time[i]);arrayList.add(listDataBean);}mRecyclerView=rootView.findViewById(R.id.rv_fra_one);listAdapter=new ListAdapter(getActivity(),arrayList);GridLayoutManager gridLayoutManager=new GridLayoutManager(getActivity(),2);gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);mRecyclerView.setLayoutManager(gridLayoutManager);mRecyclerView.setAdapter(listAdapter);}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);}}
13.activity_lesson_fragment_two.xml布局文件
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".fragment.LessonFragmentOne"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_fra_two"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>
14.activity_lesson_fragment_three.xml布局文件
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".fragment.LessonFragmentOne"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_fra_three"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>
15.activity_lesson_fragment_four.xml布局文件
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".fragment.LessonFragmentOne"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_fra_four"android:layout_width="match_parent"android:layout_height="match_parent"/></FrameLayout>
16.LessonFragmentTwo文件代码
package com.example.fragmentproject.fragment;import android.os.Bundle;import android.view.View;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.RecyclerView;import com.example.fragmentproject.R;import com.example.fragmentproject.adapter.ListAdapter;import com.example.fragmentproject.base.BaseFragment;import com.example.fragmentproject.bean.ListDataBean;import java.util.ArrayList;public class LessonFragmentTwo extends BaseFragment {private RecyclerView mRecyclerView;private ListAdapter listAdapter;private ArrayList<ListDataBean> arrayList=new ArrayList<>();private String[] headline={"网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府",};private String[] time={"2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00"};@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);}@Overrideprotected int getLayoutId(){return R.layout.activity_lesson_fragment_two;}@Overrideprotected void initView(){for (int i=0;i<6;i++){ListDataBean listDataBean=new ListDataBean(headline[i],time[i]);arrayList.add(listDataBean);}mRecyclerView=rootView.findViewById(R.id.rv_fra_two);listAdapter=new ListAdapter(getActivity(),arrayList);GridLayoutManager gridLayoutManager=new GridLayoutManager(getActivity(),2);gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);mRecyclerView.setLayoutManager(gridLayoutManager);mRecyclerView.setAdapter(listAdapter);}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);}}
17.LessonFragmentThree文件代码
package com.example.fragmentproject.fragment;import android.os.Bundle;import android.view.View;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.RecyclerView;import com.example.fragmentproject.R;import com.example.fragmentproject.adapter.ListAdapter;import com.example.fragmentproject.base.BaseFragment;import com.example.fragmentproject.bean.ListDataBean;import java.util.ArrayList;public class LessonFragmentThree extends BaseFragment {private RecyclerView mRecyclerView;private ListAdapter listAdapter;private ArrayList<ListDataBean> arrayList=new ArrayList<>();private String[] headline={"国办通报政府网站、政务新媒体检查结果","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府",};private String[] time={"2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00"};@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);}@Overrideprotected int getLayoutId(){return R.layout.activity_lesson_fragment_three;}@Overrideprotected void initView(){for (int i=0;i<8;i++){ListDataBean listDataBean=new ListDataBean(headline[i],time[i]);arrayList.add(listDataBean);}mRecyclerView=rootView.findViewById(R.id.rv_fra_three);listAdapter=new ListAdapter(getActivity(),arrayList);GridLayoutManager gridLayoutManager=new GridLayoutManager(getActivity(),2);gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);mRecyclerView.setLayoutManager(gridLayoutManager);mRecyclerView.setAdapter(listAdapter);}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);}}
18.LessonFragmentFour文件代码
package com.example.fragmentproject.fragment;import android.os.Bundle;import android.view.View;import androidx.annotation.NonNull;import androidx.annotation.Nullable;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.RecyclerView;import com.example.fragmentproject.R;import com.example.fragmentproject.adapter.ListAdapter;import com.example.fragmentproject.base.BaseFragment;import com.example.fragmentproject.bean.ListDataBean;import java.util.ArrayList;public class LessonFragmentFour extends BaseFragment {private RecyclerView mRecyclerView;private ListAdapter listAdapter;private ArrayList<ListDataBean> arrayList=new ArrayList<>();private String[] headline={"政务新媒体检查结果 网上办尖办成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府","国办通报政府网站、政务新媒体检查结果 网上办尖办”成态国办通报政府",};private String[] time={"2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00","2020-12-17 09:00"};@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);}@Overrideprotected int getLayoutId(){return R.layout.activity_lesson_fragment_four;}@Overrideprotected void initView(){for (int i=0;i<4;i++){ListDataBean listDataBean=new ListDataBean(headline[i],time[i]);arrayList.add(listDataBean);}mRecyclerView=rootView.findViewById(R.id.rv_fra_four);listAdapter=new ListAdapter(getActivity(),arrayList);GridLayoutManager gridLayoutManager=new GridLayoutManager(getActivity(),2);gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);mRecyclerView.setLayoutManager(gridLayoutManager);mRecyclerView.setAdapter(listAdapter);}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);}}
19.结果图:
20.设计图:
