网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android:帧动画

前置条件:

创新互联公司专注于鄂尔多斯企业网站建设,成都响应式网站建设公司,商城网站建设。鄂尔多斯网站建设公司,为鄂尔多斯等地区提供建站服务。全流程专业公司,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

1.首先在res/drawable目录下放入几张图片(注意图片不能用阿拉伯数字命名这里以one,two,three,four,否则在R.java文件中会报错)。

2.同样在res/drawable目录下建立animation1.xml文件,文件主要用来控制帧动画的循环次数:

android:oneshot="false"

另外还有控制播放的图片:

   
   
    
   

放在节点        的中间

3.main.xml中是对界面的布局,包括p_w_picpathview,和两个button

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

            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="帧动画图片"/>
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/linearlayout1"
    android:orientation="horizontal"
    >

    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" />

    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" />

4.接下来就是对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

   //设置资源文件获取的来源
    p_w_picpathView.setImageResource(R.drawable.animation1);
    //  // 获取AnimationDrawable对象 
    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:帧动画
文章位置:http://bjjierui.cn/article/pceopp.html

其他资讯