Android 中 Tweened animation的實例詳解
Android 中 Tweened animation的實例詳解
Tweened animation有四種類型,下面主要介紹Scale類型。
運行效果如下:
Android SDK提供了2種方法:直接從XML資源中讀取Animation,使用Animation子類的構造函數(shù)來初始化Animation對象,第二種方法在看了Android SDK中各個類的說明就知道如何使用了,下面簡要說明從XML資源中讀取Animation。XML資源中的動畫文件animation.xml內(nèi)容為:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.4" android:fromYScale="0.0" android:toYScale="1.4" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:startOffset="3000" android:duration="3000" android:repeatCount="4"/> </set>
主文件ScaleAnimation.java內(nèi)容為:
package com.android.animation; import android.app.Activity; import android.os.Bundle; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class TestAnimation extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView imageView = (ImageView) findViewById(R.id.imageview); Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation); imageView.startAnimation(animation); } }
程序很容易看懂,主要為了說明伸縮動畫效果而沒有增加復雜性。值得說明的是,本人在測試階段,錯誤的認為不需要布局文件,把行setContentView(R.layout.main);去掉,導致程序運行一直出錯。其實動畫也需要首先把布局文件加載到Activity里面,然后對布局里面的控件增加動畫。
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Android Studio中通過CMake使用NDK并編譯自定義庫和添加預編譯庫
這篇文章是基于Android Studio 3.01版本的,NDK是R16。本文重點給大家介紹Android Studio中通過CMake使用NDK并編譯自定義庫和添加預編譯庫的相關知識,感興趣的朋友一起看看吧2018-01-01Android動態(tài)加載布局實現(xiàn)技巧介紹
通過使用LayoutInflater 每次點擊按鈕時候去讀取布局文件,然后找到布局文件里面的各個VIEW 操作完VIEW 后加載進我們setContentView 方面里面的要放的布局文件里面,每次動態(tài)加載文件必需調用 removeAllViews方法,清除之前的加載進來的View2022-12-12Android系統(tǒng)view與SurfaceView的基本使用及區(qū)別分析
這篇文章主要為大家介紹了Android系統(tǒng)view與SurfaceView基本使用的案例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2022-03-03分享Android開發(fā)中最有效率最快的循環(huán)代碼
分享Android開發(fā)中最有效率最快的循環(huán)代碼,需要的朋友可以參考下2013-01-01