Android实用技巧.动画效果(二)

LayoutAnimationController实现子布局进入动画效果




以listView为例设置item进入动画:

首先设置list界面

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.administrator.androidbase.two.AnimationControllerActivity">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:cacheColorHint="@android:color/transparent"
        android:divider="#0000"
        android:dividerHeight="10px"
        android:fadingEdge="none"
        android:fastScrollEnabled="false"
        android:listSelector="#0000"
        android:scrollbars="none"  >
    </ListView>
    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ListView>
</RelativeLayout>


  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_controller);
        listView = (ListView)findViewById(R.id.listView);
        List<String> list = new ArrayList<>();
        list.add("页面1");
        list.add("页面2");
        list.add("页面3");
        list.add("页面4");
        list.add("页面5");
        list.add("页面6");
        list.add("页面7");
        list.add("页面8");
        list.add("页面9");
        list.add("页面10");
        listView.setAdapter(new ArrayAdapter<>(this,R.layout.item_layout,R.id.text
                ,list));
        initAnimation();
    }


上面不必多说,设置好界面后开始设置动画:

    private void  initAnimation(){
        //true代表动画插补器是否相同。经多次尝试设为true后,设置插补器无效
        AnimationSet animationSet = new AnimationSet(false);
        Animation animation = new AlphaAnimation(0.0f,1.0f);
        animation.setDuration(1000);
        animationSet.addAnimation(animation);
//        int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue
//        animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,1,0.0f
//                ,1,-1.0f,1,0.0f);
//        float fromXDelta, float toXDelta, float fromYDelta, float toYDelta
        animation = new TranslateAnimation(0.0f,0.0f,-100.0f,0.0f);
        animation.setDuration(1000);
        animation.setInterpolator(new BounceInterpolator());
        animationSet.addAnimation(animation);
        //子视图依次执行动画,delay代表item执行间隔,0既所以item同时执行动画效果
        LayoutAnimationController controller = new LayoutAnimationController(animationSet,0);
        listView.setLayoutAnimation(controller);
    }

插补器有很多种,在这里提供张图:


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风晴03

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值