第二十八講:Android之Animation(三)

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   ar   java   sp   

我們不得不飲食、睡眠、遊玩、戀愛,也就是說,我們不得不接觸生活中最甜蜜的事情,不過我們必須不屈服於這些事物。—— 居裡夫人


本講內容:補間動畫 Tween Animation


前面我們只學習了實現單個動畫效果,本講將同時實現多個動畫效果:

我們通過一個例子感受一下,代碼的講解都寫在注釋裡了

下面是res/layout/activity_main.xml 布局檔案:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.text.MainActivity$PlaceholderFragment" >        <ImageView        android:id="@+id/image"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1"        android:layout_gravity="center"        android:src="@drawable/c4" />    <Button        android:id="@+id/b"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:text="測試動畫效果" /></LinearLayout>

下面是建立的res/anim/alpha_rotate.xml檔案

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"android:shareInterpolator="true"><alpha android:fromAlpha="1.0"android:toAlpha="0.0"android:startOffset="500"android:duration="2000" /><rotate android:fromDegrees="0"android:toDegrees="360"android:pivotX="50%"android:pivotY="50%"android:duration="2000" /></set>
android:shareInterpolator="true"  表示裡面的一系列動畫都應用 <span style="font-family: Arial;">interpolator</span>


下面是MainActivity.java主介面檔案:

public class MainActivity extends Activity {private Button b;private ImageView image;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);b = (Button) findViewById(R.id.b);image = (ImageView) findViewById(R.id.image);AnimationButtonListener listener=new AnimationButtonListener();b.setOnClickListener(listener);}private class AnimationButtonListener implements OnClickListener {@Overridepublic void onClick(View v) {Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha_rotate);image.startAnimation(animation);}}}

下面是運行結果:可以看出一邊旋轉一邊漸層透明度



本講到這裡,謝謝大家!

第二十八講:Android之Animation(三)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.