您的位置:首页 > 其它

View从底部向上滑动出现

2016-08-12 00:00 232 查看
从屏幕底部向上滑出一个view的方式,主要是使用TranslateAnimation,这个类,可以绑定一个控件,在y轴方向,滑出一段高度,如下代码:
package com.txlong;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.TextView;

public class AndroidAnimationActivity extends Activity {

private Animation myAnimation_Translate;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final TextView tv = (TextView) findViewById(R.id.tv);
Button btn = (Button) findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setVisibility(View.VISIBLE);
myAnimation_Translate = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1,
Animation.RELATIVE_TO_PARENT, 0,
Animation.RELATIVE_TO_PARENT, 0,
Animation.RELATIVE_TO_PARENT, 0);
myAnimation_Translate.setDuration(1000);
myAnimation_Translate.setInterpolator(AnimationUtils
.loadInterpolator(AndroidAnimationActivity.this,
android.R.anim.accelerate_decelerate_interpolator));
tv.startAnimation(myAnimation_Translate);
}
});
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐