android:幀動(dòng)畫

前置條件:

創(chuàng)新互聯(lián)公司專注于鄂爾多斯企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站建設(shè)。鄂爾多斯網(wǎng)站建設(shè)公司,為鄂爾多斯等地區(qū)提供建站服務(wù)。全流程專業(yè)公司,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

1.首先在res/drawable目錄下放入幾張圖片(注意圖片不能用阿拉伯?dāng)?shù)字命名這里以one,two,three,four,否則在R.java文件中會(huì)報(bào)錯(cuò))。

2.同樣在res/drawable目錄下建立animation1.xml文件,文件主要用來(lái)控制幀動(dòng)畫的循環(huán)次數(shù):

android:oneshot="false"

另外還有控制播放的圖片:

 <item android:drawable="@drawable/one" android:duration="150"></item>  
 <item android:drawable="@drawable/two" android:duration="150"></item>  
  <item android:drawable="@drawable/three" android:duration="150"></item>  
  <item android:drawable="@drawable/four" android:duration="150"></item> 

放在節(jié)點(diǎn)<animation-list>        </animation-list>的中間

3.main.xml中是對(duì)界面的布局,包括p_w_picpathview,和兩個(gè)button

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/p_w_picpathView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:src="@drawable/four" 
        android:contentDescription="幀動(dòng)畫圖片"/>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/linearlayout1"
    android:orientation="horizontal"
    >
</LinearLayout>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/p_w_picpathView1"
    android:layout_below="@+id/p_w_picpathView1"
    android:layout_marginTop="34dp"
    android:text="@string/Begin" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignParentRight="true"
    android:text="@string/End" />

</RelativeLayout>

4.接下來(lái)就是對(duì)mainactivity.java的編寫

package com.example.bujiandonghua;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
 private AnimationDrawable animationDrawable;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final ImageView p_w_picpathView=(ImageView)findViewById(R.id.p_w_picpathView1);
  Button button1=(Button)findViewById(R.id.button1);
  Button button2=(Button)findViewById(R.id.button2);
  button1.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub

   //設(shè)置資源文件獲取的來(lái)源
    p_w_picpathView.setImageResource(R.drawable.animation1);
    //  // 獲取AnimationDrawable對(duì)象 
    animationDrawable=(AnimationDrawable)p_w_picpathView.getDrawable();
    animationDrawable.start();
   }
  });
  button2.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    p_w_picpathView.setImageResource(R.drawable.animation1);
    animationDrawable=(AnimationDrawable)p_w_picpathView.getDrawable();
    animationDrawable.stop();
   }
  });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

}

 

 

 

分享名稱:android:幀動(dòng)畫
文章URL:http://bm7419.com/article38/pceopp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、ChatGPT、Google網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)