android点赞效果,点赞 1 效果,自下而上 弹出 1提示,不错
package com.example.dianzan; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener{ private Button dianzan,dianzan_sel; private TextView textView; private android.view.animation.Animation animation; private RelativeLayout layout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); layout = (RelativeLayout) findViewById(R.id.layout); dianzan=(Button) findViewById(R.id.pro_dianzan); dianzan_sel=(Button) findViewById(R.id.pro_dianzan_sel); dianzan.setOnClickListener(this); textView=(TextView)findViewById(R.id.tv_one); animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.nn); } @Override public void onClick(View v) { if(v==dianzan){ textView.setVisibility(View.VISIBLE); textView.startAnimation(animation); new Handler().postDelayed(new Runnable(){ public void run() { textView.setVisibility(View.GONE); } }, 1000); } // 获取布局的中心点位置,作为旋转的中心点 float centerX = layout.getWidth() / 2f; float centerY = layout.getHeight() / 2f; // 构建3D旋转动画对象,旋转角度为0到90度,这使得赞将会从可见变为不可见 final Rotate3dAnimation rotation = new Rotate3dAnimation(0, 90, centerX, centerY, 310.0f, true); // 动画持续时间500毫秒 rotation.setDuration(500); // 动画完成后保持完成的状态 rotation.setFillAfter(true); rotation.setInterpolator(new AccelerateInterpolator()); // 设置动画的监听器 rotation.setAnimationListener(new TurnToImageView()); layout.startAnimation(rotation); dianzan_sel.setClickable(false); } class TurnToImageView implements AnimationListener { @Override public void onAnimationStart(Animation animation) { } /** * 当ListView的动画完成后,还需要再启动ImageView的动画,让ImageView从不可见变为可见 */ @Override public void onAnimationEnd(Animation animation) { // 获取布局的中心点位置,作为旋转的中心点 float centerX = layout.getWidth() / 2f; float centerY = layout.getHeight() / 2f; // 将赞隐藏 dianzan.setVisibility(View.GONE); // 将已赞显示 dianzan_sel.setVisibility(View.VISIBLE); // 构建3D旋转动画对象,旋转角度为270到360度,这使得赞将会从不可见变为可见 final Rotate3dAnimation rotation = new Rotate3dAnimation(270, 360, centerX, centerY, 310.0f, false); // 动画持续时间500毫秒 rotation.setDuration(500); // 动画完成后保持完成的状态 rotation.setFillAfter(true); rotation.setInterpolator(new AccelerateInterpolator()); layout.startAnimation(rotation); } @Override public void onAnimationRepeat(Animation animation) { } } }
评论