左右联动(仿京东分类)
效果图
整体布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"tools:context=".fragment.FenleiFragment"><android.support.v7.widget.RecyclerViewandroid:id="@+id/left_recycler_view"android:layout_width="0dp"android:layout_weight="3"android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView><android.support.v7.widget.RecyclerViewandroid:id="@+id/right_recycler_view"android:layout_width="0dp"android:layout_weight="7"android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView></LinearLayout>
activity或fragment
public class FenleiFragment extends Fragment implements IFenLeiView{@BindView(R.id.left_recycler_view)RecyclerView leftRecyclerView;@BindView(R.id.right_recycler_view)RecyclerView rightRecyclerView;Unbinder unbinder;private String cid = "2";private FenLeiPresenter fenLeiPresenter;private MyRightAdapter myRightAdapter;private MyLeftAdapter myLeftAdapter;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View view = inflater.inflate(R.layout.fragment_fenlei, container, false);unbinder = ButterKnife.bind(this, view);fenLeiPresenter = new FenLeiPresenter(FenleiFragment.this);fenLeiPresenter.getPresenterData();fenLeiPresenter.getRightPresenterData(cid);return view;}@Overridepublic void getViewData(String data) {Gson gson = new Gson();final FenLeiBean fenLeiBean = gson.fromJson(data, FenLeiBean.class);List<FenLeiBean.DataBean> fenLeiBeanData = fenLeiBean.getData();LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);leftRecyclerView.setLayoutManager(linearLayoutManager);//创建适配器myLeftAdapter = new MyLeftAdapter(getActivity(),fenLeiBeanData);myLeftAdapter.setSetOnItemClickListener(new MyLeftAdapter.SetOnItemClickListener() {@Overridepublic void onItemClick(int position, List<FenLeiBean.DataBean> fenLeiBeanData) {fenLeiPresenter.getRightPresenterData(fenLeiBean.getData().get(position).getCid()+"");myRightAdapter.notifyDataSetChanged();}});leftRecyclerView.setAdapter(myLeftAdapter);}@Overridepublic void onDestroyView() {super.onDestroyView();unbinder.unbind();}@Overridepublic void getRightViewData(String data) {Gson rightGson = new Gson();GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),3);rightRecyclerView.setLayoutManager(gridLayoutManager);RightBean rightBean = rightGson.fromJson(data, RightBean.class);List<RightBean.DataBean> rightBeanData = rightBean.getData();//创建适配器myRightAdapter = new MyRightAdapter(getActivity(),rightBeanData);rightRecyclerView.setAdapter(myRightAdapter);}
}
左边布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:orientation="vertical"android:layout_height="match_parent"><TextViewandroid:id="@+id/left_text_view"android:text="@string/jing"android:textSize="20sp"android:padding="10dp"android:layout_width="match_parent"android:gravity="center"android:layout_height="wrap_content" /><Viewandroid:layout_width="match_parent"android:background="#666666"android:layout_height="1dp"></View>
</LinearLayout>
左边adapter
public class MyLeftAdapter extends RecyclerView.Adapter<MyLeftAdapter.ViewHolder> {private Context context;private List<FenLeiBean.DataBean> fenLeiBeanData;private SetOnItemClickListener setOnItemClickListener;public void setSetOnItemClickListener(SetOnItemClickListener setOnItemClickListener) {this.setOnItemClickListener = setOnItemClickListener;}public MyLeftAdapter(Context context, List<FenLeiBean.DataBean> fenLeiBeanData) {this.context = context;this.fenLeiBeanData = fenLeiBeanData;}//定义接口public interface SetOnItemClickListener{void onItemClick(int position,List<FenLeiBean.DataBean> fenLeiBeanData);}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {View view = LayoutInflater.from(context).inflate(R.layout.left_layout, viewGroup, false);ViewHolder holder = new ViewHolder(view);return holder;}@Overridepublic void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int i) {viewHolder.leftTextView.setText(fenLeiBeanData.get(i).getName());viewHolder.leftTextView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {setOnItemClickListener.onItemClick(i,fenLeiBeanData);}});}@Overridepublic int getItemCount() {return fenLeiBeanData.size();}@OnClick(R.id.left_text_view)public void onViewClicked() {}public class ViewHolder extends RecyclerView.ViewHolder {@BindView(R.id.left_text_view)TextView leftTextView;public ViewHolder(View view) {super(view);ButterKnife.bind(this,view);}}
}
右边布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:orientation="vertical"android:gravity="center"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/right_img"android:layout_margin="10dp"android:layout_gravity="center"android:src="@mipmap/ic_launcher_round"android:layout_width="100dp"android:layout_height="100dp" /><TextViewandroid:id="@+id/right_text_name"android:textSize="20sp"android:text="京东"android:gravity="center"android:layout_width="match_parent"android:layout_height="wrap_content" />
</LinearLayout>
右边adapter
public class MyRightAdapter extends RecyclerView.Adapter<MyRightAdapter.ViewHolder> {private Context context;private List<RightBean.DataBean> rightBeanData;public MyRightAdapter(Context context, List<RightBean.DataBean> rightBeanData) {this.context = context;this.rightBeanData = rightBeanData;}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {View view = LayoutInflater.from(context).inflate(R.layout.rightlayout, viewGroup, false);ViewHolder holder = new ViewHolder(view);return holder;}@Overridepublic void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {Glide.with(context).load(rightBeanData.get(i).getList().get(i).getIcon()).into(viewHolder.rightImg);viewHolder.rightTextName.setText(rightBeanData.get(i).getName());}@Overridepublic int getItemCount() {return rightBeanData.size();}public class ViewHolder extends RecyclerView.ViewHolder {@BindView(R.id.right_img)ImageView rightImg;@BindView(R.id.right_text_name)TextView rightTextName;public ViewHolder(@NonNull View itemView) {super(itemView);ButterKnife.bind(this,itemView);}}
}
左右联动(仿京东分类)相关推荐
- android京东商城一级分类到二级分类的滑动效果,Android仿京东分类模块左侧分类条目效果...
本文实例为大家分享了Android仿京东左侧分类条目效果的具体代码,供大家参考,具体内容如下 import android.app.Activity; import android.os.Bundle ...
- 仿京东 分类 购物车 + 定位
依赖================================================================= apply plugin: 'com.android.appli ...
- listview的分类,仿京东分类
listview的分类,今天看到京东的app分类做的很ok,自己也尝试了下,效果实现了. //先上图,京东的,我自己的 //代码很容易就不过多做解释了. //主要的话就是两个方法的使用 //listv ...
- 小程序完美实现仿京东商城分类列表
做小程序也有一段时间了,现在将一个仿京东分类列表的源码分享给大家, 先看效果图: 下载地址
- 仿京东App分类页面的实现
今天群里有人问了关于仿京东App分类页面的实现,而我之前正好查过这方面的资料,手上正好有一个demo,正好分享给大家看看,个人觉得效果棒棒哒! 首先来看效果图吧 是不是很6呢,来分析这个demo的主体 ...
- 仿京东、饿了么 左右联动菜单列表自定义View
仿京东.饿了么 左右联动菜单列表 这是一个左右联动的自定义View 这里本人将两个列表进行了联动封装,使用的时候调用方法即可,方便快捷,扩展性也强. 完整Demo传送门 效果图: 正题开始: 我们看一 ...
- vue 实现仿京东、淘宝省市区三级联动
vue 实现仿京东.淘宝省市区三级联动 在做电商或其他项目的时候,物流我们肯定会集成进去,那么我们肯定需要集成地址管理,地址管理除了最基本的省.市.区外,我们还要单独添加一个详细地址字段,不然我们无法 ...
- h5仿android 京东三级联动,jquery仿京东商城三级联动代码插件
2019-3-1更新:location.js文件里第三级县之前使用京东旧域名d.360buy.com的jsonp数据,域名做了跳转首页所以第三加载不出来.现在已经更新为d.jd.com,正常加载.不过 ...
- 仿京东APP分类页面(mvp模式+OkHttp封装工具类+拦截器+弱引用回收)
仿京东APP分类页面: 添加依赖 compile 'com.android.support:recyclerview-v7:24.0.0' compile 'com.google.code.gson: ...
最新文章
- 初步认识pg_control文件之一
- 字节跳动2019暑期实习生算法岗笔试题
- c语言制表符_随时随地学习C语言之1—开发环境搭建
- 【Java网络编程(一)】IP地址、端口、URL、网络爬虫原理、TCP UDP协议
- mybatis collection标签_一对多的关系,在MyBatis中如何映射?
- 如何延长作用域链_通过实例理解javaScript中的this到底是什么和它的词法作用域...
- 单表置换密码java代码实现_单表替换密码
- 失去了商标品牌的迅雷大数据,变成了摸金狗?
- ROS的学习(十)rqt_console和roslaunch
- DataGridView绑定list的注意事项
- 对于文章的字母、单词、短语,(无用词表)的检索Java代码实现
- Linux安装MATLAB Compiler Runtime操作
- 【工具】(七):win10常用工具整理!!!
- 简单的STM32汇编程序
- 安徽科技学院 信网学院网络文化节 陈鑫鑫
- 键值数据库的基本架构
- Edge与Safari双向同步书签
- 字节跳动二面:你能说说“抖音直播”怎么测试么?
- 抖音不搞「盲目」社交
- 053试题 334/682 - crosscheck