android动画之Translation
来源:互联网 发布:php高并发 编辑:程序博客网 时间:2024/05/03 13:35
Activity:
import android.app.Activity;
import android.os.Bundle;import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
private LinearLayout allView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
allView = (LinearLayout) findViewById(R.id.all_view);
for (int i = 0; i < allView.getChildCount(); i++) {
allView.getChildAt(i).setVisibility(View.GONE);
}
animView(allView.getChildCount() - 1, 200);
}
private void animView(final int position, final long deloy) {
if (position < 0)
return;
View view = allView.getChildAt(position);
view.setVisibility(View.VISIBLE);
TranslateAnimation transAnimation = (TranslateAnimation) AnimationUtils
.loadAnimation(this, R.anim.anim_in_from_top);
transAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animView(position - 1, deloy / 2);
}
}, deloy / 2);
}
// -deloy / 3 + 100 * position
// (long) -deloy / 3 + 200 * position
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
view.startAnimation(transAnimation);
}
}
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/all_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ff0000ff"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ffff00ff"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:id="@+id/tv3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ff00ff00"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:id="@+id/tv4"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ff00ffff"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
动画文件:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fillAfter="true"
android:fromYDelta="-100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toYDelta="0%p" >
</translate>
- android动画之Translation
- android Translation
- Android wiki:11.translation平称进出动画
- Android Property Animation属性动画初识:位移translation(3)
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- 【Android动画】之Frame动画
- Android 动画之属性动画
- Android动画之:Frame动画
- Android动画之图片动画
- Android动画之属性动画
- Android动画之布局动画
- Android动画之属性动画
- android 动画 之 属性动画
- Android动画之---帧动画
- Android动画之---属性动画
- 统计java方法(函数)的代码行数
- iOS中各种图片的要求 App Icons on iPad and iPhone
- SqlServer 2000 LinkSever 建立,出现 该访问接口支持该接口,但使用该接口时返回了失败代码。
- iOS开发UI篇—从代码的逐步优化看MVC
- RadioButton单选按钮
- android动画之Translation
- iOS 网络编程 NSURLSessionDataTask 添加cookie
- c++之运行时类型识别
- SpringMVC 源代码深度解析(context:component-scan)(扫描和注册的注解Bean)
- 1.百钱买白鸡
- 关于面试的一些事
- 2012年5月SAT香港真题解析
- HTTP协议详解
- swift 反向过渡