Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画


第一个动画文件btn_anim.xml
<?xml version="1.0" encoding="utf-8"?>

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator">
<!--位移动画    -->
    <translate
        android:fromXDelta="0.0"
        android:fromYDelta="0.0"
        android:toXDelta="0.0"
        android:toYDelta="-75.0"
        android:duration="750"
        android:fillBefore="true"
        android:fillAfter="true" />

<!--缩放动画    -->

<scale android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="1.05" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="350" android:fillBefore="true" android:fillAfter="true"/></set>

2-在res文件夹 anim文件夹下面,建立第二个文件layout_anim.xml):

<?xml version="1.0" encoding="utf-8"?>

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator">

    <scale
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="0.95"
        android:toYScale="0.95"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="100"
        android:fillBefore="true"
        android:fillAfter="true"/>

</set>

3主activity 我是在fragment中使用,你就随意吧。

...
private ScrollView scrollView; // This is my container. Yours may be different
private Animation btnAnim;
private Animation layoutAnim;
...

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        // Getting context
        context = getActivity().getApplicationContext();

        btnAnim = AnimationUtils.loadAnimation(context, R.anim.btn_anim);
        btnAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                layoutAnim = AnimationUtils.loadAnimation(context, R.anim.layout_anim);
                scrollView.startAnimation(layoutAnim);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        // create view
        View view = inflater.inflate(R.layout.fragment_browse_single, container, false);

        scrollView = (ScrollView) view.findViewById(R.id.scrollView);

        myButton = (Button) view.findViewById(R.id.myButton);
        myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnZan.startAnimation(btnAnim);
            }
        });

        Log.i(TAG, "View created");
        return view;
    }




另一种demo做法。试用了线程。不推荐使用


public class applaudAnimation extends Activity implements OnClickListener {       private Button button;     private TextView textView;     private android.view.animation.Animation animation;       public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.animation);           animation = AnimationUtils.loadAnimation(this,R.anim.applaud_animation);         button = (Button) findViewById(R.id.bt);         button.setOnClickListener(this);         textView = (TextView) findViewById(R.id.animation);     }       @Override     public void onClick(View v) {         if (v == button) {             textView.setVisibility(View.VISIBLE);             textView.startAnimation(animation);             new Handler().postDelayed(new Runnable() {                 public void run() {                     textView.setVisibility(View.GONE);                 }             }, 1000);         }       } }
animation.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#ffffff" >       <Button         android:id="@+id/bt"         android:layout_width="40dip"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:gravity="center"         android:text="赞"         android:textColor="#000000"         android:textSize="18dip" />       <TextView         android:id="@+id/animation"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:gravity="center"         android:text="+1"         android:textColor="#FF0000"         android:textSize="18dip"         android:visibility="gone" />   </RelativeLayout>
  
applaud_animation.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android">   <translate     android:fromXDelta="0"     android:toXDelta="0"     android:fromYDelta="0"     android:toYDelta="-50"     android:duration="1000"/>       <alpha     android:fromAlpha="1.0"     android:toAlpha="0.3"     android:duration="1000"/> </set>
时间: 2024-08-09 23:42:41

Android点赞动画效果 ,点赞后加一,2种方法,①补间动画②位移动画的相关文章

BMC hang后恢复的几种方法

BMC hang住后恢复的几种方法 在服务器上一般都会有BMC来检测系统并报告系统的健康状况,从而保证服务器的连续稳定运行.由于BMC本身也是一个由硬件.操作系统.监控应用程序组成的软硬件系统,本身也可能发生故障,甚至导致无法响应系统发过来的IPMI请求,这就是所谓的BMC hang.那么,当BMC出现hang的情景后,有哪些措施可以尝试恢复呢? 首先,可以尝试重新加载服务器端host上BMC的驱动,可以运行下面命令去检查之前IPMI驱动有没有加载: [[email protected] ~]#

Android在布局中动态添加view的两种方法

一.说明 添加视图文件的时候有两种方式:1.通过在xml文件定义layout:2.java代码编写 二.前言说明 1.构造xml文件 2.LayoutInflater 提到addview,首先要了解一下LayoutInflater类.这个类最主要的功能就是实现将xml表述的layout转化为View的功能.为了便于理解,我们可以将它与findViewById()作一比较,二者都是实例化某一对象,不同的是findViewById()是找xml布局文件下的具体widget控件实例化,而LayoutI

【Android】Eclipse自动编译NDK/JNI的三种方法

[Android]Eclipse自动编译NDK/JNI的三种方法 SkySeraph Sep. 18th  2014 Email:[email protected] 一.Eclipse关联cygwin 1. 工程->右击选择Properties->选择Builders,在Builders中选择New创建一个Program 2. 参数配置 二.Eclipse关联ndk-build(自建Builder方法)  1. Project->Properties->Builders->N

Android实现计时与倒计时(限时抢购)的几种方法

在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但后来考虑在安卓中是否有更佳的方案,于是乎共找到以下五种实现方案,另外还有一种使用CountDownTimer进行计时的方面,我 会在单独的文章中进行介绍 效果如图: 方法一 Timer与TimerTask(Java实现) [java] view plaincopy public class time

[转]Android实现计时与倒计时(限时抢购)的几种方法

在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但后来考虑在安卓中是否有更佳的方案,于是乎共找到以下五种实现方案,另外还有一种使用CountDownTimer进行计时的方面,我会在单独的文章中进行介绍 效果如图: 方法一 Timer与TimerTask(Java实现) [java] view plaincopy public class timer

Android中使用Gson解析JSON数据的两种方法

Json是一种类似于XML的通用数据交换格式,具有比XML更高的传输效率;本文将介绍两种方法解析JSON数据,需要的朋友可以参考下 Json是一种类似于XML的通用数据交换格式,具有比XML更高的传输效率. 从结构上看,所有的数据(data)最终都可以分解成三种类型: 第一种类型是标量(scalar),也就是一个单独的字符串(string)或数字(numbers),比如"北京"这个单独的词. 第二种类型是序列(sequence),也就是若干个相关的数据按照一定顺序并列在一起,又叫做数组

Android监听点击事件实现的三种方法

监听点击事件实现的三种方法:1.匿名内部类2.外部类3.直接实现接口 1.匿名内部类: package com.jereh.calculator; import android.content.Context; import android.os.Bundle; import android.os.PersistableBundle; import android.support.design.widget.FloatingActionButton; import android.support

Android 通过代码设置radiobutton不同方位图标的两种方法

更换radiobutton中的图片在xml中很好设置,但对于初学者如何在代码中设置还是不容易找的.没法子,通过看原版api找到两个方法,setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds. 下面交给大家方法. 第一个方法:setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) ap

动画效果一风火轮加载效果/动态图展示

#import "ViewController.h" @interface ViewController () // 可视化编程拖出的UIImageView属性 @property (weak, nonatomic) IBOutlet UIImageView *imageView; // 定义数组存放图片组 @property (nonatomic,strong)NSMutableArray *imagesArr; // 定义活动指示器(风火轮)属性 @property (nonato

android MPAndroidChart饼图实现图例后加数字或文本(定制图例)

转载请注明:http://blog.csdn.net/ly20116/article/details/50905789 MPAndroidChart是一个非常优秀的开源图表库,MPAndroidChart可以绘制各种常用的图表类型:折线图.柱形图.饼图.散点图等等. github地址:https://github.com/PhilJay/MPAndroidChart 具体的导入方式就不再详细的说了,本文主要解决在图例后面加上数字或文本或占的百分比等,也就是定制想要的图例. MPAndroidCh