仿京东顶部加载动画

  昨天的时候我们仿照了一个美团的加载的图标的小人,今天我们也来看看京东在下拉刷新的时候也会有一个快递的小人是怎么实现的,还是依靠惯例,我们解压一下它的apk,然后去里面找一找那些素材,发现原来也有几张图片,原来它的原理是和美团是一样的,其他的就不多说了。

  • 我们先把素材取出来再说:
    这里写图片描述 这里写图片描述 这里写图片描述 这里写图片描述
  • 接下来我们就在drawable 目录下新建一个 loading_jd.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/app_refresh_people_0" android:duration="60"></item>
    <item android:drawable="@drawable/app_refresh_people_1" android:duration="60"></item>
    <item android:drawable="@drawable/app_refresh_people_2" android:duration="60"></item>
    <item android:drawable="@drawable/app_refresh_people_3" android:duration="60"></item>

</animation-list>
  • 然后我们在我们的布局文件中的使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:gravity="center"
    >

    <ImageView
        android:id="@+id/iv_loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/loading_jd"
        android:layout_gravity="center"
        />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dip"
        android:textSize="18sp"
        android:text="加载中。。。"
        />

</LinearLayout>
  • 3、接下来我们就在Activity中开启帧动画
public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_main);

        ImageView iv_loading = (ImageView) findViewById(R.id.iv_loading);
        AnimationDrawable loadingDrawable = (AnimationDrawable) iv_loading.getDrawable();
        loadingDrawable.start();
    }
}

其实这个动画是非常简单的,就是利用了Android里面的帧动画来实现的,通过多张图片的无限循环的播放来达到这个效果,最后我们看看这个效果与我们的效果是不是一样的。
这里写图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值