点滴 Android程序员Android开发

怎么快速简单的打造一个炫酷的ListView

2016-06-08  本文已影响1062人  乆丩乣

在上一篇View动画里,我们知道了View动画以及帧动画的简单使用,而这一篇主要是讲View动画的特殊使用场景,比如:

关于Activity切换这点,这篇帖子就不细说了无非就是overridePendingTransition的使用,本文主要要说的是LayoutAnimation

LayoutAnimatioon

LayoutAnimation作用于ViewGroup,为ViewGroup指定一个动画,这样他的子元素出场时都会具有这种动画

LayoutAnimatioon中的属性:
LayoutAnimatioon的使用遵循以下几个步骤:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/anim_item"
    android:animationOrder="normal"
    android:delay="0.5">
</layoutAnimation>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:shareInterpolator="true">
    <alpha
        android:fromAlpha="0"
        android:toAlpha="1.0" />
    <translate
        android:fromXDelta="500"
        android:toXDelta="0" />
</set>
在xml布局文件中指定android:layoutAnimation属性:
<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff4f7f9"
    android:cacheColorHint="#00000000"
    android:divider="#dddbdb"
    android:dividerHeight="1.0px"
    android:layoutAnimation="@anim/layout_animation"
    android:listSelector="@android:color/transparent"
/>
或者,可以在java代码中通过LayoutAnimationController来指定:
ListView listview = (ListView) findViewById(R.id.listview);
Animation animation = AnimationUtils.loadAnimation(TestAnimActivity.this, R.anim.anim_item);
LayoutAnimationController controller = new LayoutAnimationController(animation);
controller.setDelay(0.5f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
listview.setLayoutAnimation(controller);

怎么样,如此简单就能做出一个炫酷的ListView特效,so easy!

================================================
更多内容请关注 我的专题
转载请注明 原文链接:
http://www.jianshu.com/users/c1b4a5542220/latest_articles

上一篇 下一篇

猜你喜欢

热点阅读