布局
第一种 简短位移动画
final View bot = findViewById(R.id.bot);
Button but = findViewById(R.id.but);
bot.setTranslationY(600);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bot.animate()
.translationY(0)
.setDuration(2000)
.withLayer()
.start();
}
});
final View bot = findViewById(R.id.bot);
Button but = findViewById(R.id.but);
bot.post(new Runnable() {
@Override
public void run() {
final ViewGroup.LayoutParams layoutParams = bot.getLayoutParams();
int height = layoutParams.height;
layoutParams.height = 0;
bot.setLayoutParams(layoutParams);
valueAnimator = ValueAnimator.ofInt(0, height);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int mAnimatorValue = (int) valueAnimator.getAnimatedValue();
layoutParams.height = mAnimatorValue;
bot.setLayoutParams(layoutParams);
}
});
}
});
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
valueAnimator.start();
}
});