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
     <span id= "1_nwp" style= "width: auto; height: auto; float: none;" ><a id= "1_nwl" href= "http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Ejcodecraeer%2Ecom%2Fa%2Fanzhuokaifa%2Fandroidkaifa%2F2014%2F0920%2F1698%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=01072140_cpr&k=android&k0=android&kdi0=8&k1=%B6%AF%BB%AD&kdi1=8&k2=%B5%E7%D7%D3%CF%E0%B2%E1&kdi2=8&sid=861a9a46d40c70b6&ch=0&tu=u1921070&jk=015869c8e072c03f&cf=29&rb=0&fv=16&stid=9&urlid=0&luki=1&seller_id=1&di=128" target= "_blank" mpid= "1" style= "text-decoration: none;" ><span style= "color:#0000ff;font-size:14px;width:auto;height:auto;float:none;" >android</span></a></span>:id= "@+id/image"
     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);

 

  

  

你可能感兴趣的:(animation)