自定义view实现《最美有物》点赞效果
来源:互联网 发布:淘宝网超市货架 编辑:程序博客网 时间:2024/05/17 09:30
最近在博客中发现了一篇关于最美有物app上的点赞效果实现于是自己也做了一个demo最美有物效果图如下
在这里其实有两个动画一个是不断上升的动画然后是小人笑脸或者无感的动画逐渐上升的动画使用属性动画逐渐改变view的margin或者padding即可笑脸或者无感的动画使用逐帧动画即可。
布局代码如下
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_iv_bg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/shap_round_yellow" android:orientation="vertical"> <ImageView android:id="@+id/iv_yellow_smail" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="center_horizontal" android:contentDescription="@string/app_name" android:src="@drawable/animation_like" /></LinearLayout>
然后是自定义布局代码的处理
public class DianZanView extends LinearLayout { LinearLayout llBg; ImageView ivSmail; public DianZanView(Context context) { this(context, null); } public DianZanView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public DianZanView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater.from(context).inflate(R.layout.item_dianzan, this); llBg = findViewById(R.id.ll_iv_bg); ivSmail = findViewById(R.id.iv_yellow_smail); } public void startAnimUp() { ValueAnimator upAnim = ValueAnimator.ofFloat(0, 300).setDuration(3000); upAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { LinearLayout.LayoutParams layoutParams = (LayoutParams) ivSmail.getLayoutParams(); float bottomMargin = (float) animation.getAnimatedValue(); layoutParams.setMargins(0, 0, 0, (int) bottomMargin); ivSmail.setLayoutParams(layoutParams); if (bottomMargin == 300) { AnimationDrawable animationDrawable = (AnimationDrawable) ivSmail.getDrawable(); animationDrawable.stop(); animationDrawable.start(); } } }); upAnim.start(); } public void startAnimDown() { }}
代码只实现了一部分剩下的加一些处理逻辑即可
参考
自定义控件 | 仿《最美有物》点赞效果
资源地址
点赞效果代码
阅读全文
0 0
- 自定义view实现《最美有物》点赞效果
- 自定义View-仿即刻点赞效果
- Android 自定义View 实现QQ红点拖动删除效果
- 自定义View实现SeekBar点值选择效果(一)
- 自定义View实现点值选择效果(二)
- 自定义View实现刮刮卡效果
- 自定义View实现SwichButton效果
- 自定义 View 实现钟表效果
- 自定义View实现索引效果
- 自定义view实现炸弹效果
- 自定义控件 | 仿《最美有物》点赞效果
- 自定义view之点赞
- 自定义View实现转盘旋转效果
- 自定义view实现图文环绕的效果
- 自定义view实现水波荡漾的效果
- android自定义view实现progressbar的效果
- 自定义view实现水波纹效果
- 自定义view实现水波纹效果
- A quick complete tutorial to save and restore Tensorflow models
- 前端开发学习总结
- windows7下安装python库face_recognition
- TensorFlow学习笔记(三)
- 微信h5支付,微信外浏览器支付实现
- 自定义view实现《最美有物》点赞效果
- 学习笔记
- 请求服务报Error parsing HTTP request header
- center os 6.5无线网路适配
- 利用 boost 库,编写c++类 FilesDirectoryTree,获得某个文件夹下符合某种格式要求(pcd)的文件路径,并按照降序或升序排列
- php扩展配置方法
- Qml图片转灰度
- 游戏开发笔记之二——最简单的DirectX,vc窗口的编写
- 大黑哥seo:SEO快速排名算法技术原理揭秘