Android帧动画实现

文章主要介绍了安卓帧动画的实现过程。

下面是java代码,其实很简单,关键的地方就四行:

public class MainActivity extends Activity {

    private ImageView refreshView;
    private AnimationDrawable animationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        refreshView = (ImageView) findViewById(R.id.refreshView);
        refreshView.setImageResource(R.drawable.refresh_animation);
        animationDrawable = (AnimationDrawable) refreshView.getDrawable();
        animationDrawable.start();
    }
}
以下是布局文件的代码:

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:id="@+id/refresh">

        <RelativeLayout
            android:layout_marginLeft="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/refreshView"
                android:src="@drawable/f1"
                android:layout_marginLeft="50dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <LinearLayout
                android:orientation="vertical"
                android:layout_toRightOf="@id/refreshView"
                android:layout_marginTop="20dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/refreshTextOne"
                    android:text="正在刷新数据..."
                    android:textColor="@color/material_blue_grey_950"
                    android:textSize="15sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/refreshTextTwo"
                    android:text="松手更新"
                    android:textColor="#50000000"
                    android:layout_marginTop="4dp"
                    android:textSize="12sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

实现这一过程最重要的一步就是在drawable下新建refresh_animation.xml文件,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <item android:drawable="@drawable/f1" android:duration="150"></item>
    <item android:drawable="@drawable/f2" android:duration="150"></item>
    <item android:drawable="@drawable/f3" android:duration="150"></item>
    <item android:drawable="@drawable/f4" android:duration="150"></item>
    <item android:drawable="@drawable/f5" android:duration="150"></item>
    <item android:drawable="@drawable/f6" android:duration="150"></item>
    <item android:drawable="@drawable/f7" android:duration="150"></item>
    <item android:drawable="@drawable/f8" android:duration="150"></item>


</animation-list>

duration可以设置图片更换的时间长短。

大家可以试试,只是实现以下效果,最终效果没有问题。

另注,这里有一篇很好的关于安卓动画的文章值得学习入门:http://www.2cto.com/kf/201410/342375.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值