要实现的效果:

MainActivity核心代码:

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mTvRecycler.setLayoutManager(layoutManager);
mMyRecyclerViewAdapter = new MyRecyclerViewAdapter(TvStationActivity.this,mList);
//给RecyclerView设置适配器
mTvRecycler.setAdapter(mMyRecyclerViewAdapter);

activity_main.xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:app="http://schemas.android.com/apk/res-auto"><android.support.v7.widget.RecyclerViewandroid:id="@+id/tv_recycler"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginBottom="25dp"android:layout_marginEnd="8dp"android:layout_marginStart="8dp"android:layout_marginTop="8dp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"></android.support.v7.widget.RecyclerView></android.support.constraint.ConstraintLayout>

Adapter 适配器:外层RecyclerView

/*** @author 小红妹* @date 2018/10/20.* @describe* @copyright */public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ItemViewHolder> {private Context mContext;private List<String> mDatas;private ItemViewHolder holder;private ItemRecyclerViewAdapter mItemRecyclerViewAdapter;public MyRecyclerViewAdapter (Context pContext,List<String> data){this.mContext = pContext;this.mDatas = data;}class ItemViewHolder extends RecyclerView.ViewHolder {TextView mTextView;RecyclerView mRecyclerView;ItemViewHolder(View itemView) {super(itemView);mTextView = itemView.findViewById(R.id.tv_recycler_name);mRecyclerView = itemView.findViewById(R.id.tv_recycler_view);}}@NonNull@Overridepublic ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {//LayoutInflater.from指定写法View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_content, parent, false);//holder = new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_content, parent, false));return new ItemViewHolder(v);}@Overridepublic void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {holder.mTextView.setText(mDatas.get(position));holder.mRecyclerView.setHasFixedSize(true);holder.mRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 4,GridLayoutManager.VERTICAL, false));mItemRecyclerViewAdapter = new ItemRecyclerViewAdapter(position);holder.mRecyclerView.setAdapter(mItemRecyclerViewAdapter);drawRecyclerView();}@Overridepublic int getItemCount() {return mDatas.size();}/*** RecyclerView 内层点击事件方法*/private void drawRecyclerView() {//RecyclerView点击事件mItemRecyclerViewAdapter.setOnItemClickListener(new ItemRecyclerViewAdapter.OnItemClickListener() {@Overridepublic void onItemClick(View view, int position) {Toast.makeText(mContext, ""+position, Toast.LENGTH_SHORT).show();}});}}

RecyclerView外层布局item_home_content.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="wrap_content"><TextViewandroid:id="@+id/tv_recycler_name"android:layout_width="match_parent"android:layout_height="45dp"android:layout_marginStart="8dp"android:layout_marginTop="8dp"android:text="TextView"android:textSize="19sp"android:gravity="center_vertical"android:background="@color/whitesmoke"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><android.support.v7.widget.RecyclerViewandroid:id="@+id/tv_recycler_view"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginEnd="8dp"android:layout_marginStart="8dp"android:layout_marginTop="8dp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/tv_recycler_name"></android.support.v7.widget.RecyclerView></android.support.constraint.ConstraintLayout>

Adapter 适配器:内层RecyclerView

/*** @author 小红妹* @date 2018/10/20.* @describe* @copyright*/public class ItemRecyclerViewAdapter extendsRecyclerView.Adapter<ItemRecyclerViewAdapter.MyViewHolder> implements View.OnClickListener {private int mInt;private Home mHome;private List<Home> mHomes;private String[] localTV = new String[]{"湖南卫视", "江苏卫视", "浙江卫视", "东方卫视","北京卫视", "安徽卫视", "山东卫视", "深圳卫视","江西卫视", "黑龙江台", "广东卫视", "天津卫视","湖北卫视", "河北卫视", "重庆卫视", "东南卫视","甘肃卫视", "广西卫视", "贵州卫视", "河南卫视","吉林卫视", "辽宁卫视", "旅游卫视", "内蒙古台","宁夏卫视", "青海卫视", "四川卫视", "陕西卫视","山西卫视", "新疆卫视", "西藏卫视", "云南卫视","南方卫视", "香港卫视", "凤凰中文", "凤凰资讯"};private String[] cctv = new String[]{"CCTV1", "CCTV2", "CCTV3", "CCTV4","CCTV5", "CCTV5+", "CCTV6", "CCTV7","CCTV8", "CCTV9", "CCTV10", "CCTV11","CCTV12", "CCTV13", "CCTV14", "CCTV15","央视音乐", "央视军事", "央视新闻", "央视少儿"};private String[] mLocal = new String[]{"广州新闻", "广州经济", "广州少儿", "广州综合","广东新闻", "南方卫视", "南方经济", "广东珠江","南方影视", "南方综艺", "深圳都市", "深圳公共","金华公共", "温州经济", "温州都市", "嘉兴综合"};private String[] mSports = new String[]{"CCTV5", "CCTV5+", "广东体育", "五星体育","北京体育", "风云足球", "广州竞赛", "欧洲足球"};private String[] mMusic = new String[]{"华龙直播", "经典串烧", "伤感男人", "发烧慢摇","汽车大碟", "酒吧慢摇", "激情舞曲", "电音舞曲"};private String[] mFilm = new String[]{"央视电影", "家庭剧场", "喜剧电影", "动作电影","经典剧场", "热播电视", "都市剧场", "经典大片"};private String[] mCartoon = new String[]{"嘉佳卡通", "北京卡酷", "金鹰卡通", "炫动卡通"};//新建一个私有变量用于保存用户设置的监听器private OnItemClickListener mOnItemClickListener = null;//set方法:public void setOnItemClickListener(OnItemClickListener listener) {this.mOnItemClickListener = listener;}@Overridepublic void onClick(View v) {if (mOnItemClickListener != null) {//注意这里使用getTag方法获取positionmOnItemClickListener.onItemClick(v,(int)v.getTag());}}//define interface 自定义一个接口public static interface OnItemClickListener {void onItemClick(View view, int position);}public ItemRecyclerViewAdapter(int pI){mHomes = new ArrayList<>();//holder.mView.setText(localTV[i]);if (pI == 0) {for (int i = 0; i < localTV.length; i++) {mHome = new Home();mHome.setName(localTV[i]);mHomes.add(mHome);}}if (pI == 1) {for (int i = 0; i < cctv.length; i++) {mHome = new Home();mHome.setName(cctv[i]);mHomes.add(mHome);}}if (pI == 2) {for (int i = 0; i < mLocal.length; i++) {mHome = new Home();mHome.setName(mLocal[i]);mHomes.add(mHome);}}if (pI == 3) {for (int i = 0; i < mSports.length; i++) {mHome = new Home();mHome.setName(mSports[i]);mHomes.add(mHome);}}if (pI == 4) {for (int i = 0; i < mMusic.length; i++) {mHome = new Home();mHome.setName(mMusic[i]);mHomes.add(mHome);}}if (pI == 5) {for (int i = 0; i < mFilm.length; i++) {mHome = new Home();mHome.setName(mFilm[i]);mHomes.add(mHome);}}if (pI == 6) {for (int i = 0; i < mCartoon.length; i++) {mHome = new Home();mHome.setName(mCartoon[i]);mHomes.add(mHome);}}}@NonNull@Overridepublic MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_head,null);//将创建的View注册点击事件view.setOnClickListener(this);return new MyViewHolder(view);}@Overridepublic void onBindViewHolder(@NonNull MyViewHolder holder, int position) {holder.mView.setText(mHomes.get(position).getName());//将position保存在itemView的Tag中,以便点击时进行获取holder.itemView.setTag(position);}@Overridepublic int getItemCount() {return mHomes.size();}public class MyViewHolder extends RecyclerView.ViewHolder {TextView mView;public MyViewHolder(View itemView) {super(itemView);mView = itemView.findViewById(R.id.tv_name);}}
}

RecyclerView内层布局item_home_head.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns: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="wrap_content"><!--android:background="@drawable/beautiful_linearlayout_border"--><TextViewandroid:id="@+id/tv_name"android:layout_width="wrap_content"android:layout_height="48dp"android:layout_marginStart="0dp"android:layout_marginTop="0dp"android:gravity="center"android:text="TextView"android:textSize="19sp"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>

Android RecyclerView 子条目(item)嵌套 RecyclerView相关推荐

  1. android recyclerview,AndroidRecyclerView中的Item嵌套RecyclerView使用实例

    最近项目中有一个需求是RecyclerView中的Item中嵌套RecyclerView,在网上没找到什么资料,然后就自己尝试了一下. 首先看一下效果图 录制GIF现在不大方便,就直接上两个图了. 关 ...

  2. RecyclerView 嵌套RecyclerView 或者 ScrollView当中嵌套RecyclerView ,子View会自动滚动到顶部

    问题如图 此问题一开始我以为是我在fragment当中,返回和移动的时候调用了adpater的notifyItemChange方法情况和notifyItemChanged(int position) ...

  3. Android之解决CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+RecyclerView里面再嵌套RecyclerView滑动颤抖问题

    1 问题 主页面用的是这种结构 CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+RecyclerView(里面再嵌套RecyclerVie ...

  4. Recyclerview嵌套Recyclerview,条目显示不全和宽度不能铺满不能同时满足

    参考了: RecyclerView常见问题解决方案,RecyclerView嵌套自动滚动,RecyclerView 高度设置wrap_content 无作用等问题 - 邱石的专栏 - CSDN博客   ...

  5. 【Android 界面效果49】RecyclerView高度随Item自适应

    编写RecyclerView.ItemDecoration时,在onDraw方法中,Drawable的高度等于RecyclerView的高度减去RecyclerView的上下padding. @Ove ...

  6. android view嵌套,Android RecyclerView嵌套RecyclerView点击事件

    RecyclerView嵌套RecyclerView点击事件遇到取值错乱的问题 其实问题根本就是咱们没有处理好被嵌套的那层recycleview的position 那么解决思路也很简单,想办法把被嵌套 ...

  7. Android 入门第四讲03-列表RecyclerView(RecyclerView使用步骤(详),RecyclerView指定一行item的数目+指定一行item的数量,并且设置列表方向)

    Android 入门第四讲03-列表RecyclerViewRecyclerView使用步骤(详),RecyclerView指定一行item的数目+指定一行item的数量,并且设置列表方向) 1.Re ...

  8. android 继承relativelayout,Android自定义View(RelativeLayout),并嵌套(recyclerView)

    自定义view嵌套使用,简单操作. 一:简单的自定义view(relativeLayout) public class ViewRelativeLayout extends RelativeLayou ...

  9. Android中RecyclerView嵌套RecyclerView或嵌套ListView

    Android中RecyclerView嵌套RecyclerView或嵌套ListView

  10. Android SrcollView嵌套recyclerView的使用

    今天,简单讲讲Android里使用SrcollView嵌套recyclerView需要注意的地方. 不废话了直接上代码,在使用时加上下面的代码就可以 recyclerView.setLayoutMan ...

最新文章

  1. Windows 8 应用商店应用开发 之 画刷
  2. PyTorch 实现经典模型8:FCN
  3. boost实用工具:assign库了解学习
  4. ERROR 1045 (28000): Access denied for user'root'@'localhost'(using password:YES)
  5. suse10 linux安装,SuSE10.2 安装手记
  6. asp无组件上传图片 动态保存文件名 upload.inc逐句翻译
  7. 计算机原理及应用课程,课程描述
  8. JAVA后台权限管理系统
  9. CC攻击(Challenge Collapsar)原理及防范方法
  10. html重复渐变包括,CSS3怎么实现重复线性渐变效果
  11. 什么是指纹浏览器,修改浏览器指纹工具
  12. win10修改用户名/指纹无法置入/用户文件没有重命名的选项
  13. 奥威软件联手省科干,全力打造大数据BI岗位技能实践基地
  14. node 压缩图片_用图压批量压缩图片就这么简单
  15. 用ADC0809实现八通道采集
  16. bboss quartz定时任务使用案例介绍
  17. Int16, Int32, Int64 范围
  18. 代号Pie!Android 9.0那些开发者必须知道的事
  19. 基于美团Leaf-Segment的双buffer方案实现序列号生成器
  20. 力扣 560. 和为 K 的子数组

热门文章

  1. JAVA网络编程实战(笔记)
  2. 短信轰渣器搭建源码下载
  3. java数据同步视频,Oracle从入门到精通 oracle数据库 全程同步视频教学 内含Oracle Java项目实战教...
  4. 跳过密码卸载OfficeScan
  5. 【教程】Edraw Max使用教程:创建一个基本流程图
  6. 电驴搜索服务器正在连接,电驴emule eD2k 不能连接服务器解决办法
  7. [渝粤教育] 四川农业大学 农业气象学 参考 资料
  8. 《深入浅出统计学》读书笔记
  9. 《数据库原理》— 数据库系统概论第五版习题解析
  10. 【WP 8.1开发】如何把自定义字体塞进应用里