视图动画

Android中视图动画是由5种类型组成:alpha、scale、translate、rotate、set.
alpha:渐变透明度动画效果
scale:渐变尺寸伸缩动画效果
translate:画面变换位置移动动画效果
rotate:画面转移旋转动画效果
set:定义动画集
一、新建一个工程,然后右击res


图片.png

图片.png

图片.png

图片.png

二、示例演示
1、新建一个布局文件

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>
    <TextView
        android:id="@+id/textview"
        android:layout_gravity="center_horizontal"
        android:background="@android:color/darker_gray"
        android:text="Hello"
        android:layout_width="100dp"
        android:layout_height="100dp"/>
</LinearLayout>

2、代码中使用

public class MainActivity extends AppCompatActivity {
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        Button button = (Button)findViewById(R.id.button);
        final TextView textview = (TextView)findViewById(R.id.textview);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation animation = AnimationUtils.loadAnimation(context,R.anim.alphaanim);
                textview.startAnimation(animation);
            }
        });
    }
}

三、alpha:实现渐变透明度动画效果
1、示例演示

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="1.0"
    android:toAlpha="0.1"
    android:duration="3000"
    android:fillBefore="true">
</alpha>
备注:参数说明
android:fromAlpha:动画开始的透明度,从0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明
android:toAlpha:动画结束时的透明度,也是从0.0 --1.0 ,0.0表示全透明,1.0表示完全不透明
android:duration      动画持续时间,以毫秒为单位
android:fillBefore      如果设置为true,控件动画结束时,还原到开始动画前的状态

四、scale:渐变尺寸伸缩动画效果
五、translate:画面变换位置移动动画效果
六、rotate:画面转移旋转动画效果
七、set:定义动画集

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容