android 头部折叠,Android 头像折叠效果
一、前言:
我们在开发中,经常遇到头像折叠效果,特别是直播软件,以前都是写死的,太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 头像折叠效果相关推荐
- Android 使用RecycleView制作头像堆叠效果
效果如下: 代码如下: 这里给出部分关键代码 逻辑代码: //反方向排列recycleView.layoutManager = LinearLayoutManager(this, LinearLayo ...
- android 实现控件搜索折叠效果 Animation动画折叠和普通折叠
android 实现控件搜索折叠效果 Animation动画折叠和普通控件直接折叠效果: 原理很简单,都是获取对应的高度,通过实现高度变化而改变显示效果: 话不多说直接上代码 1.普通折叠效果,以下是 ...
- android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(一)
第二篇文章链接: android RecyclerView一步步打造分组效果.类似QQ分组.折叠菜单.分组效果(二) 效果图: 前言 之前看到这种效果如果用recyclerview来实现没有一点思路, ...
- android 百叶窗动画,Android 百叶窗折叠效果
blinds.png 其实这个标题的类比并不太准确,百叶窗高度是固定的,只是 Z 轴有旋转.折叠效果并没有体现出来.不过毕竟自己一开始想到这个名字,那就硬着头皮也要叫这名字啦. 缘由 在微信的「聊天信 ...
- android RecyclerView一步步打造分组效果、类似QQ分组、折叠菜单、分组效果(二)
第一篇链接: android RecyclerView一步步打造分组效果.类似QQ分组.折叠菜单.分组效果(一) 注!已更新代码! 上一篇写了分组效果的初步实现: 这一篇就继续增加分组折叠效果和基类的 ...
- Android折叠屏开发学习(三)---使用MotionLayout实现折叠屏分屏效果
学更好的别人, 做更好的自己. --<微卡智享> 本文长度为6259字,预计阅读11分钟 前言 今天是折叠屏开发的第三篇,前面已经介绍了铰链的角度监听和Jetpack Window实现监听 ...
- android 伸缩工具栏,看,这个工具栏能伸缩折叠——Android CollapsingToolbarLayout使用介绍...
我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...
- android可折叠窗口,Android Studio使用recyclerview实现展开和折叠功能(在之前的微信页面基础之上)...
Android中RecyclerView点击item展开列表详细内容 效果如下: 依然是xml文件的设计,使用了两个RelativeLayout,zu作为主布局和副布局,里面都加入textview显示 ...
- android隐藏toolbar,Android CoordinatorLayout的使用——实现Toolbar的隐藏和折叠
简单介绍下CoordinatorLayout CoordinatorLayout public class CoordinatorLayout extends ViewGroup implements ...
最新文章
- Android stadio 导入不在当前工程目录里的工程
- typeScript面试必备之-通识七:typeScript中的可索引接口(数组,对象)+类类型接口...
- Redis学习笔记--Redis数据过期策略详解
- 诺依曼原理中计算机由运算器,冯诺依曼原理与计算机的基本组成
- junit4/5 getDefaultClassLoader()Ljava/lang/ClassLoader;
- Spring 中常用的设计模式对比
- USB 协议分析之 HID 设备(转)
- Aspose.Word
- 基于SSM的闲猫二手商城
- Gateway配合sentinel自定义限流_Spring Cloud Gateway网关如何快速实施限流方案?-Part 6...
- python人脸比对算法_用Python实现一个简单的——人脸相似度对比
- 超级详细的java Collection集合面试题
- 前端基础入门课程推荐
- 计算机作业实验报告dw感想,Dreamweaver实验报告.doc
- Android Design in Action — 以微信为例
- Linux系统日志查询
- Verilog语法之变量
- 国防科大计算机学院卢凯,国防科技大学实行本硕、硕博连读机制
- 中国ABS市场发展前景与投资策略建议报告2022-2028年
- 关于Multisim仿真电容充电曲线的设置方法