ApiDemo学习 炫酷的 layoutAnimation

本文介绍Android中多种视图动画的实现方式,包括GridView、ListView的动画效果设置及使用XML和代码实现的具体方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

所在包:com.example.android.apis.view

apidemo还是有非常多的好东西的 作为初学者 必须看啊

首先是一个一个叠下来的动画


很简单  gridview中的:

android:layoutAnimation="@anim/layout_grid_fade"

<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/fade"
    android:directionPriority="column"
    android:rowDelay="50%" />

fade

<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/fade"
    android:directionPriority="column"
    android:rowDelay="50%" />

然后是listview 的从上面甩下来:

AnimationSet set = new AnimationSet(true);

        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(50);
        set.addAnimation(animation);

        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
        );
        animation.setDuration(100);
        set.addAnimation(animation);

        LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
        ListView listView = getListView();        
        listView.setLayoutAnimation(controller);

向上甩上去

演示用用xml实现

android:layoutAnimation="@anim/layout_bottom_to_top_slide"

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/slide_right"
    android:animationOrder="reverse"
    android:delay="30%" />

slide_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="-100%p" android:toXDelta="0"
            android:duration="@android:integer/config_shortAnimTime" />
</set>


GridView 随机显示item

 android:layoutAnimation="@anim/layout_random_fade"


<?xml version="1.0" encoding="utf-8"?>

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

fade

<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/fade"
    android:directionPriority="column"
    android:rowDelay="50%" />


从下到上的显示item

<?xml version="1.0" encoding="utf-8"?>

<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:columnDelay="0.5"
        android:directionPriority="row"
        android:direction="right_to_left|bottom_to_top"
        android:animation="@anim/fade" />
其他两个感觉不是很好 不介绍了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值