zoukankan      html  css  js  c++  java
  • Android.Hack.02_Animations

    #01# TextView 和 ImageView

      TextView和Imageview切换卡顿,为了实现更好的切换,可以用动画来实现,系统自带的TextViewSwitcher 和ImageViewSwitcher,其中设置自定义动画,可以使用如下Demo:

      

    private TextSwitcher mTextSwitcher;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); setContentView(R.layout.main);   Animation in = AnimationUtils.loadAnimation(this,   android.R.anim.fade_in);   Animation out = AnimationUtils.loadAnimation(this,   android.R.anim.fade_out);   mTextSwitcher = (TextSwitcher) findViewById(R.id.your_textview);   mTextSwitcher.setFactory(new ViewFactory() {
    @Override
    public View makeView() { TextView t = new TextView(YourActivity.this); t.setGravity(Gravity.CENTER);
    //21 Adding eye candy to your ViewGroup’s children
    return t; } }); mTextSwitcher.setInAnimation(in); mTextSwitcher.setOutAnimation(out); }

    参考链接:http://developer.android.com/reference/android/widget/TextSwitcher.html

         http://developer.android.com/guide/topics/graphics/view-animation.html

    #02# 为viewgroup的children添加动画-----LayoutAnimationController

      例子是最好的诠释:

        mListView = (ListView) findViewById(R.id.my_listview_id);

               AnimationSet set = new AnimationSet(true);
               Animation animation = new AlphaAnimation(0.0f, 1.0f);
              animation.setDuration(50);
              set.addAnimation(animation);
             animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
             Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
             - 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
             animation.setDuration(100);
             set.addAnimation(animation);
              LayoutAnimationController controller = new LayoutAnimationController(
             set, 0.5f);
    Create LayoutAnimationController
    and delay between animations. mListView.setLayoutAnimation(controller);

    参考链接:http://developer.android.com/reference/android/view/animation/LayoutAnimationController.html
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    #03# Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果

        Nine Old Androids 亦可以实现,图片的缩放的效果,跟官方API里面的图片效果一样。即是::Ken Burns特效,

      比较详细的Demo,已经有人翻译过了:

      :http://blog.csdn.net/manoel/article/details/39164225

    一个实现Ken Burns effect图片展示效果的效果android控件。Ken Burns effect是一种图片在切换之前,会缓慢在页面移动或者放大缩小,然后再慢慢切换过去。这样的效果使得每一张静止图片都有动态的效果感觉。类似的效果在电子相册,或者在电影视频对静态图片的处理中经常可见。

    项目地址https://github.com/flavioarfaria/KenBurnsView

    用法:

    最简单的用法是直接将项目中提供的jar文件放入,然后在xml中添加:

    1
    2
    3
    4
    5
    <com.flaviofaria.kenburnsview.KenBurnsView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/your_drawable" />

    高级用法:

    1.设置listener:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    KenBurnsView kbv = (KenBurnsView) findViewById(R.id.image);
    kbv.setTransitionListener(new TransitionListener() {
        @Override
        public void onTransitionStart(Transition transition) {
        }
        @Override
        public void onTransitionEnd(Transition transition) {
        }
    });

    2.你可以用kbv.pause() 和 kbv.resume();暂停和恢复动画。

    3.你可以设置动画的插值和过度时间:

    1
    2
    RandomTransitionGenerator generator = new RandomTransitionGenerator(duration, interpolator);
    kbv.setTransitionGenerator(generator);

     

      

      

  • 相关阅读:
    应用程序如何实现高级量规界面自定义?这个第三方控件很好用
    Web应用开发的透视网格如何实现本地化?一招教你轻松搞定
    这个布局助手工具,帮你快速构建美观的WinForm应用
    用于Delphi的DevExpress VCL组件——增强布局控件性能
    JS/TS生成随机姓名
    单例模式的错误用法
    Node极速开发WebSocket服务器
    Unity中实现WebSocket客户端
    解决git每次输入密码的问题
    html转md
  • 原文地址:https://www.cnblogs.com/spring87/p/4252484.html
Copyright © 2011-2022 走看看