#Android学习#Animation之布局动画

本文介绍了Android中布局动画的使用,特别是在LinearLayout中如何实现TextView等元素的动画效果。接着,通过代码动态生成及资源文件的方式,展示了在RecyclerView中实现Item出现时的从右往左移动动画。涉及关键概念包括LayoutAnimationController、setLayoutAnimation以及RecyclerView的动画配置。
摘要由CSDN通过智能技术生成

上次简单介绍了Animation的使用,那是通过点击button,触发动画效果,比如旋转按钮。这次学习的Animation主要是用于布局,即layout中的动画效果,比如LinearLayout里面,TextView空间出现时的动画效果。控制layout中的动画效果,主要是利用LayoutAnimationController和setLayouAnimation来实现。我们先介绍Animation在布局中的使用,最后以RecylerView为例,实现每个item出现时是从右往左移动过来。

LinearLayou中的Animation

新建一个Android Studio Project(选择默认,直接下一步即可),首先,我们在content_main.xml 中添加几个TextView(其他控件也可以,比如Button),每个TextView中设置text为One、Two、Three。

//content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.cyfloel.learnlayoutanimation.MainActivity"
    android:animateLayoutChanges="true"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="One" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值