NineOldAndroidsDemos 学习(1) Toggles
2013-10-24 08:46
316 查看
NineOldAndroidsDemos(http://nineoldandroids.com/) 是一个让3.0一下的应用也可以使用Animator的开源项目,
所以接触android也有不少时间了,但是使用animator却很少,所以借此机会学习一下animator的使用.
首先是Toggles
这个是最简单的animator的使用
很简单 只要使用ObjectAnimator/ofFloat就可以对某个view进行动画,比animation是不是更快一些?
所以接触android也有不少时间了,但是使用animator却很少,所以借此机会学习一下animator的使用.
首先是Toggles
这个是最简单的animator的使用
很简单 只要使用ObjectAnimator/ofFloat就可以对某个view进行动画,比animation是不是更快一些?
public class Toggles extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.toggles); final View target = findViewById(R.id.target); final int duration = 2 * 1000; findViewById(R.id.tx).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "translationX", 0, 50, -50, 0).setDuration(duration).start(); } }); findViewById(R.id.ty).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "translationY", 0, 50, -50, 0).setDuration(duration).start(); } }); findViewById(R.id.sx).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "scaleX", 1, 2, 1).setDuration(duration).start(); } }); findViewById(R.id.sy).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "scaleY", 1, 2, 1).setDuration(duration).start(); } }); findViewById(R.id.a).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "alpha", 1, 0, 1).setDuration(duration).start(); } }); findViewById(R.id.rx).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "rotationX", 0, 180, 0).setDuration(duration).start(); } }); findViewById(R.id.ry).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "rotationY", 0, 180, 0).setDuration(duration).start(); } }); findViewById(R.id.rz).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ObjectAnimator.ofFloat(target, "rotation", 0, 180, 0).setDuration(duration).start(); } }); findViewById(R.id.pivot_zero_zero).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ViewHelper.setPivotX(target, 0); ViewHelper.setPivotY(target, 0); } }); findViewById(R.id.pivot_center).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ViewHelper.setPivotX(target, target.getWidth() / 2f); ViewHelper.setPivotY(target, target.getHeight() / 2f); } }); findViewById(R.id.pivot_width_height).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ViewHelper.setPivotX(target, target.getWidth()); ViewHelper.setPivotY(target, target.getHeight()); } }); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/tx" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TX"/> <Button android:id="@+id/ty" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="TY"/> <Button android:id="@+id/sx" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="SX"/> <Button android:id="@+id/sy" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="SY"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/a" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Alpha"/> <Button android:id="@+id/rx" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="RX"/> <Button android:id="@+id/ry" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="RY"/> <Button android:id="@+id/rz" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="RZ"/> </LinearLayout> <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal"> <Button android:id="@+id/pivot_zero_zero" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="Pivot (0,0)"/> <Button android:id="@+id/pivot_center" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="Pivot Center"/> <Button android:id="@+id/pivot_width_height" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="Pivot (w,h)"/> </LinearLayout> <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent" android:layout_weight="1" android:gravity="center"> <Button android:id="@+id/target" android:layout_width="100dp" android:layout_height="100dp" android:text="Sample Text" android:gravity="center"/> </LinearLayout> </LinearLayout>
相关文章推荐
- NineOldAndroidsDemos 学习(5) AnimationCloning 和 AnimationLoading
- NineOldAndroidsDemos 学习(2) ViewPropertyAnimator
- NineOldAndroidsDemos 学习(8) MultiPropertyAnimation ReversingAnimation
- NineOldAndroidsDemos 学习(4) FlakeView
- NineOldAndroidsDemos 学习(9) CustomEvaluator
- NineOldAndroidsDemos 学习(3) PathAnimationActivity
- NineOldAndroidsDemos 学习(6) AnimationSeeking 和 AnimatorEvents
- NineOldAndroidsDemos 学习(7) BouncingBalls
- nineoldandroids学习笔记
- nineoldandroids学习笔记
- 8. Android框架和工具之 NineOldAndroids(动画框架)
- NineOldAndroids:Android 3.0 Animation API的适配库
- 我的C++学习历程(old)
- NineOldAnimations 设计解析
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- NineOldAndroids 使用
- Android 开源动画框架 NineOldAndroids
- NineOldAndroids在低版本系统的使用中点击事件滞留在原来位置的处理
- nineOldAnimation 应用
- Android动画进阶—使用开源动画库nineoldandroids