Android.Hack.02_Animations

來源:互聯網
上載者:User

標籤:

#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中添加:

12345 <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:

123456789 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.你可以設定動畫的插值和過度時間:

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

 

  

  

Android.Hack.02_Animations

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.