012 Android 动画效果(补间动画) +去掉App默认自带的标题+更改应用的图标
1.介绍
补间动画开发者只需指定动画开始,以及动画结束"关键帧", 而动画变化的"中间帧"则由系统计算并补齐!
2.去掉App的标题
(1)将AndroidManifest文件中Application标签中内容保持不变。
android:theme="@style/AppTheme"(即默认设置).
(2)修改values->styles.xml中的设置
将以下内容:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
替换为:
<resources> <!-- Base application theme. --> <!--<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">--> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources>
3.修改应用显示的图标
AndroidManifest文件中,将以下代码进行修改。
(1)修改前
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
(2)修改后
<application android:allowBackup="true" android:icon="@mipmap/icon_150" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
4.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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/bt_touming" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="透明" /> <Button android:id="@+id/bt_xuanzhuan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="旋转" /> <Button android:id="@+id/bt_suofang" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="缩放" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" app:srcCompat="@mipmap/ic_launcher" /> </LinearLayout> </LinearLayout>
5.java后台
package com.example.administrator.test60donghua; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { Button bt_touming; Button bt_xuanzhuan; Button bt_suofang; ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt_touming=findViewById(R.id.bt_touming); bt_xuanzhuan=findViewById(R.id.bt_xuanzhuan); bt_suofang=findViewById(R.id.bt_suofang); iv=findViewById(R.id.imageView); //透明动画 bt_touming.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //创建透明动画,1.0为完全不透明,0.0为完全透明 AlphaAnimation aa=new AlphaAnimation(1.0f,0.0f); aa.setDuration(2000);//设置动画执行的时间 aa.setRepeatCount(1); //设置动画重复的次数 aa.setRepeatMode(Animation.REVERSE); //设置重复的模式 iv.startAnimation(aa); //开始执行动画 } }); //旋转效果 bt_xuanzhuan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RotateAnimation ra=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); ra.setDuration(2000);//设置动画执行的时间 ra.setRepeatCount(1); //设置动画重复的次数 ra.setRepeatMode(Animation.REVERSE); //设置重复的模式 iv.startAnimation(ra); //开始执行动画 } }); bt_suofang.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ScaleAnimation sa=new ScaleAnimation(1.0f,2.0f,1.0f,2.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); sa.setDuration(2000);//设置动画执行的时间 sa.setRepeatCount(1); //设置动画重复的次数 sa.setRepeatMode(Animation.REVERSE); //设置重复的模式 iv.startAnimation(sa); //开始执行动画 } }); } }
6.效果图
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)