实现点赞和收藏效果
来源:互联网 发布:大拿韩代 淘宝 编辑:程序博客网 时间:2024/05/29 10:10
实现点赞和收藏的效果
github地址:https://github.com/Taonce/support 点击打开链接
效果:
布局代码:
<ImageView android:id="@+id/ivCollect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" android:layout_gravity="center" android:layout_margin="20dp" android:src="@mipmap/blackheart" android:background="?android:attr/selectableItemBackgroundBorderless" />
动画效果:
public class ScaleAnimatorUtils { //设置缩放动画,淡入和淡出 public static void setScale(View view) { //创建一个AnimatorSet对象 AnimatorSet set = new AnimatorSet(); //设置动画的时间和效果 ObjectAnimator animator_x = ObjectAnimator.ofFloat(view, "scaleX", 1.5f, 1.2f, 1f, 0.5f, 0.7f, 1f); ObjectAnimator animator_y = ObjectAnimator.ofFloat(view, "scaleY", 1.5f, 1.2f, 1f, 0.5f, 0.7f, 1f); set.play(animator_x).with(animator_y); //设置他的持续时间 set.setDuration(500); //启动动画 set.start(); }}
点击效果:
@Overridepublic void onClick(View view) { switch (view.getId()) { case R.id.ivCollect: if (ivCollect.isSelected() == false) { ivCollect.setImageResource(R.mipmap.redheart); ivCollect.setSelected(true); ScaleAnimatorUtils.setScale(ivCollect); Toast.makeText(MainActivity.this,"收藏成功",Toast.LENGTH_SHORT).show(); } else { ivCollect.setImageResource(R.mipmap.blackheart); ivCollect.setSelected(false); ScaleAnimatorUtils.setScale(ivCollect); Toast.makeText(MainActivity.this,"取消收藏",Toast.LENGTH_SHORT).show(); } break; }}
这里我们主要就是用到了ObjectAnimotor对象,调用他的ofFloat (Object target, String propertyName, float... values)方法,设置目标View和动画参数。
阅读全文
1 0
- 实现点赞和收藏效果
- html超级简单实现点赞(收藏)和取消赞效果
- 使用Notification实现点赞、收藏功能
- SurfaceView实现点赞效果
- SurfaceView实现点赞效果
- jquery实现收藏效果
- js点赞效果++和--
- 一步一步实现Periscope点赞效果
- 一步一步实现Periscope点赞效果
- 即刻app 点赞效果实现
- 自定义view实现《最美有物》点赞效果
- 点赞收藏动画
- 利用redis实现收藏或者点赞数量的累加
- ajax 点赞收藏功能
- Android 之 点赞+收藏
- Android 之 点赞+收藏
- TextView实现红点效果
- Android点波纹效果实现
- 新建unittest的步骤
- 图论---求割点,求桥(tarjan) (模板)
- Linux服务器内外网端口转发映射
- Matlab绘图中的对象容器(Object Containers)
- 【Android】如何实现启动APP时引导页、欢迎页功能设置之(二)设置只在第一次启动APP时跳入引导界面
- 实现点赞和收藏效果
- Spark-2.1.0-hadooop-2.6.0-cdh5.7.0源码编译
- 设置mysql自动运行
- Android获取系统信息---获取CPU数
- 华为校招上机编程之““字符串的分割””
- 热更新 AndFixDemo
- 禁止from disk cache,禁止浏览器缓存问题
- android 公共顶部栏
- java-反射