您的位置:首页 > 其它

仿京东顶部加载动画

2015-11-21 14:35 169 查看
  昨天的时候我们仿照了一个美团的加载的图标的小人,今天我们也来看看京东在下拉刷新的时候也会有一个快递的小人是怎么实现的,还是依靠惯例,我们解压一下它的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里面的帧动画来实现的,通过多张图片的无限循环的播放来达到这个效果,最后我们看看这个效果与我们的效果是不是一样的。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: