Android 给listview/gridview设置加载动画(逐条加载条目动画)

来源:互联网 发布:网站域名备案注册证书 编辑:程序博客网 时间:2024/06/06 17:30

1、先写出需要的动画效果list_anim.xml

<?xml version="1.0" encoding= "utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- android:duration="1500" 动画持续时间 -->    <!-- android:fillAfter="true" 动画结束时停留在结束位置 -->    <!-- android:fromAlpha="0.0" 动画起始透明度:透明 -->    <!-- android:toAlpha="1.0" 动画结束透明度:显示 -->    <alpha        android:duration="2000"        android:fillAfter="true"        android:fromAlpha="0.0"        android:toAlpha="1.0" /></set>
2、写出动画加载文件gridview_anim.xml

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"    android:animation="@anim/list_anim"    android:animationOrder="normal"    android:delay="0.5" />

3、在GridView的布局中配置动画activity_main.xml

<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"    tools:context="hjk.anim.grid.MainActivity" >    <GridView        android:id="@+id/gridView"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:numColumns="3"        android:cacheColorHint="@android:color/transparent"        android:drawSelectorOnTop="false"        android:fadingEdgeLength="0.0dp"        android:layoutAnimation="@anim/gridview_anim"        android:listSelector="#ffffff" /></RelativeLayout>


之后在代码中加载GridView的Item文件就可以看到动画加载GridView Item的效果


0 0
原创粉丝点击