一、前言:

我们在开发中,经常遇到头像折叠效果,特别是直播软件,以前都是写死的,太Low了,今天用recycleView实现头像折叠效果:

效果图.png

1、项目依赖:

//recyclerview使用

implementation 'com.android.support:recyclerview-v7:28.0.0'

// glide的使用

implementation 'com.github.bumptech.glide:glide:4.6.1'

2、item_message_tip主布局

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="@dimen/dp_70"

tools:ignore="MissingConstraints"

android:gravity="center"

android:orientation="horizontal"

android:id="@+id/ll_layout"

>

android:id="@+id/ll_tip"

android:layout_width="wrap_content"

android:layout_height="@dimen/dp_40"

android:background="@drawable/round_19_f1f3f6"

android:orientation="horizontal"

>

android:id="@+id/rv_message"

android:layout_marginLeft="@dimen/dp_4"

android:layout_width="wrap_content"

android:layout_height="@dimen/dp_40"/>

android:id="@+id/tv_message"

android:layout_marginLeft="@dimen/dp_10"

android:layout_marginRight="@dimen/dp_14"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="1条新消息"

android:textSize="@dimen/sp_14"

android:textColor="@color/color_FF333333"

android:layout_gravity="center_vertical"

/>

3、业务逻辑

private void initTopMessage() {

ll_layout = topMessage.findViewById(R.id.ll_layout);

ll_tip = topMessage.findViewById(R.id.ll_tip);

TextView tv_message = topMessage.findViewById(R.id.tv_message);

RecyclerView rvMessage = topMessage.findViewById(R.id.rv_message);

List list = new ArrayList<>();

list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597150953412&di=46e8b9da62a00e93dc048d68be84565f&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201503%2F18%2F20150318223723_vZrrA.jpeg");

list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1597150875198&di=0c9488318607f40319c61ca4a94c05d4&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201710%2F18%2F20171018230400_5zmuJ.jpeg");

list.add("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3715807199,284763637&fm=26&gp=0.jpg");

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);//这里的true和false控制堆叠的方向,我的效果右侧堆叠所以是false

linearLayoutManager.setStackFromEnd(true);

rvMessage.setLayoutManager(linearLayoutManager);

ItemImageAdapter imageAdapter = new ItemImageAdapter(R.layout.item_image_adapter, list);

rvMessage.setAdapter(imageAdapter);

tv_message.setText("6条新消息");

//进入消息列表

ll_tip.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

//新评论

//新评论

Intent intent = new Intent(getContext(), MessageNewCommentActivity.class);

intent.putExtra("type", "11");

intent.putExtra("type_name", "被评论");

startActivityForResult(intent, CommonConstant.RESULT_COMMENT_CODE);

}

});

}

4、ItemImageAdapter

public class ItemImageAdapter extends BaseQuickAdapter {

public ItemImageAdapter(int layoutResId, @Nullable List data) {

super(layoutResId, data);

}

@Override

protected void convert(@NonNull BaseViewHolder helper, String item) {

int position = helper.getLayoutPosition();

//为0是不折叠(核心)

if(position==0){

setMargins(helper.itemView,0,0,0,0);

}

ImageView header = helper.getView(R.id.header);

GlideUtils.showImageViewToCircle(BaseApplication.mContext,item,header);

}

public void setMargins (View v, int l, int t, int r, int b) {

if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {

ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();

p.setMargins(l, t, r, b);

v.requestLayout();

}

}

}

5、item_image_adapter子布局

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/relayout"

android:layout_width="wrap_content"

android:layout_height="@dimen/dp_40"

android:layout_marginLeft="-6dp"

>

android:id="@+id/header"

android:layout_width="@dimen/dp_30"

android:layout_height="@dimen/dp_30"

android:layout_centerVertical="true"

android:src="@drawable/my_default_head"

android:scaleType="fitXY" />

android 头部折叠,Android 头像折叠效果相关推荐

  1. Android 使用RecycleView制作头像堆叠效果

    效果如下: 代码如下: 这里给出部分关键代码 逻辑代码: //反方向排列recycleView.layoutManager = LinearLayoutManager(this, LinearLayo ...

  2. android 实现控件搜索折叠效果 Animation动画折叠和普通折叠

    android 实现控件搜索折叠效果 Animation动画折叠和普通控件直接折叠效果: 原理很简单,都是获取对应的高度,通过实现高度变化而改变显示效果: 话不多说直接上代码 1.普通折叠效果,以下是 ...

  3. android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(一)

    第二篇文章链接: android RecyclerView一步步打造分组效果.类似QQ分组.折叠菜单.分组效果(二) 效果图: 前言 之前看到这种效果如果用recyclerview来实现没有一点思路, ...

  4. android 百叶窗动画,Android 百叶窗折叠效果

    blinds.png 其实这个标题的类比并不太准确,百叶窗高度是固定的,只是 Z 轴有旋转.折叠效果并没有体现出来.不过毕竟自己一开始想到这个名字,那就硬着头皮也要叫这名字啦. 缘由 在微信的「聊天信 ...

  5. android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(二)

    第一篇链接: android RecyclerView一步步打造分组效果.类似QQ分组.折叠菜单.分组效果(一) 注!已更新代码! 上一篇写了分组效果的初步实现: 这一篇就继续增加分组折叠效果和基类的 ...

  6. Android折叠屏开发学习(三)---使用MotionLayout实现折叠屏分屏效果

    学更好的别人, 做更好的自己. --<微卡智享> 本文长度为6259字,预计阅读11分钟 前言 今天是折叠屏开发的第三篇,前面已经介绍了铰链的角度监听和Jetpack Window实现监听 ...

  7. android 伸缩工具栏,看,这个工具栏能伸缩折叠——Android CollapsingToolbarLayout使用介绍...

    我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...

  8. android可折叠窗口,Android Studio使用recyclerview实现展开和折叠功能(在之前的微信页面基础之上)...

    Android中RecyclerView点击item展开列表详细内容 效果如下: 依然是xml文件的设计,使用了两个RelativeLayout,zu作为主布局和副布局,里面都加入textview显示 ...

  9. android隐藏toolbar,Android CoordinatorLayout的使用——实现Toolbar的隐藏和折叠

    简单介绍下CoordinatorLayout CoordinatorLayout public class CoordinatorLayout extends ViewGroup implements ...

最新文章

  1. Android stadio 导入不在当前工程目录里的工程
  2. typeScript面试必备之-通识七:typeScript中的可索引接口(数组,对象)+类类型接口...
  3. Redis学习笔记--Redis数据过期策略详解
  4. 诺依曼原理中计算机由运算器,冯诺依曼原理与计算机的基本组成
  5. junit4/5 getDefaultClassLoader()Ljava/lang/ClassLoader;
  6. Spring 中常用的设计模式对比
  7. USB 协议分析之 HID 设备(转)
  8. Aspose.Word
  9. 基于SSM的闲猫二手商城
  10. Gateway配合sentinel自定义限流_Spring Cloud Gateway网关如何快速实施限流方案?-Part 6...
  11. python人脸比对算法_用Python实现一个简单的——人脸相似度对比
  12. 超级详细的java Collection集合面试题
  13. 前端基础入门课程推荐
  14. 计算机作业实验报告dw感想,Dreamweaver实验报告.doc
  15. Android Design in Action — 以微信为例
  16. Linux系统日志查询
  17. Verilog语法之变量
  18. 国防科大计算机学院卢凯,国防科技大学实行本硕、硕博连读机制
  19. 中国ABS市场发展前景与投资策略建议报告2022-2028年
  20. 关于Multisim仿真电容充电曲线的设置方法

热门文章

  1. 深圳软件测试培训学习:网络基础 — ping命令(1)
  2. mongodb数据库的常用命令
  3. HBase(5):HBase进阶
  4. js中 new原理及实现
  5. 企业入驻腾讯公益平台步骤
  6. 前端使用XLSX导出表格
  7. 小程序微信支付完整demo源码,包含退款
  8. 显卡驱动又双叒叕怎么办?
  9. paip.花生壳 服务启动失败 以及不能安装服务,权限失败的解决
  10. 【转载】如何巧用IPD,建立完善的产品研发管理体系?