第12天~

继续开工~intent 的搜寻关键字-android intent action

https://developer.android.com/guide/components/intents-filters?hl-zh-tw#java

电话跟简讯模拟器不能测试.因为没有绑电信....


动画-老师说没有人会花很多时间在看动画的!!!只会播一次

先建立XML档排版-

https://ithelp.ithome.com.tw/upload/images/20220201/20119035jOTK4w6uh1.png

button也是要绑定onclick

https://ithelp.ithome.com.tw/upload/images/20220201/201190352qSOXKuNKz.png

还没有onclick就会反红
https://ithelp.ithome.com.tw/upload/images/20220201/20119035ohRaZBteiT.png

package com.huang.myapplication9;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onclick(View view) {
    }
}

改照片的地方-Common Attributes-srcCompat
https://ithelp.ithome.com.tw/upload/images/20220201/20119035hMDZ6qNGR8.png

要往下选图模拟器才可以看到

https://ithelp.ithome.com.tw/upload/images/20220201/201190354spep9eUkz.png

https://ithelp.ithome.com.tw/upload/images/20220201/20119035ENWJWcBcuy.png

https://ithelp.ithome.com.tw/upload/images/20220201/20119035LLy9Apl0DP.png


新增-资源类资料夹

https://ithelp.ithome.com.tw/upload/images/20220201/20119035EI5aUYoKbN.png

开始~

https://ithelp.ithome.com.tw/upload/images/20220201/20119035m5ODBtYS6x.png

选anim产生动画资料夹

https://ithelp.ithome.com.tw/upload/images/20220201/201190353gbCs428K6.png

选长这样~按OK

https://ithelp.ithome.com.tw/upload/images/20220201/20119035bf7vVi9wdg.png

https://ithelp.ithome.com.tw/upload/images/20220201/20119035yMEDOXkLvN.png

在anim上选anim... resoure file 会跳出

https://ithelp.ithome.com.tw/upload/images/20220201/20119035NAVIx918Zg.png

Root element的set是动画"组"的意思

https://ithelp.ithome.com.tw/upload/images/20220201/20119035WEKnGOlmID.png

https://ithelp.ithome.com.tw/upload/images/20220201/20119035gvwa6UUSpf.png


动画的内容就是由小变到大

也是包头尾同
https://ithelp.ithome.com.tw/upload/images/20220201/20119035fP88lPcF4R.png

单位不写就是以%计算
android:pivotX="50%"一定要写%

duration要自己打要以毫秒来写..1秒=1000毫秒

预设是300毫秒

android:duration="2000"

https://ithelp.ithome.com.tw/upload/images/20220201/20119035yz0uCA31Ko.png

<scale
         android:fromXScale="1.0"
         android:fromYScale="1.0"
         android:toXScale="3.0"
         android:toYScale="3.0"
         android:pivotX="50%"
         android:pivotY="50%"
         android:duration="2000"
       />

动画的内容就是由小变到大..再由大变到小

anim01.xml程序码:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- 缩放 -->
     <scale
         android:fromXScale="1.0"
         android:fromYScale="1.0"
         android:toXScale="3.0"
         android:toYScale="3.0"
         android:pivotX="50%"
         android:pivotY="50%"
         android:duration="2000"
       />
     <scale
         android:fromXScale="3.0"
         android:fromYScale="3.0"
         android:toXScale="1.0"
         android:toYScale="1.0"
         android:pivotX="50%"
         android:pivotY="50%"
         android:duration="2000"
         />

</set>

用ctrl c+ctrl v 产生3个anim01.xml

https://ithelp.ithome.com.tw/upload/images/20220201/20119035IOZVe3RZML.png
再来一个一个改~
anim02.xml程序码:呈现旋转 角度0 正转-写一组就好不然没反应

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- 旋转 -->
     <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotY="50%"
        android:pivotX="50%"
        android:duration="2000"
        />
    

</set>


anim03.xml程序码: 移动+透明度(1.0可看见+0.0看不见)-只会播一次

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- 移动 -->
     <translate
         android:fromXDelta="20"
         android:fromYDelta="100"
         android:toXDelta="500"
         android:toYDelta="300"
         android:duration="2000"
          />
     <translate
         android:fromXDelta="100"
         android:fromYDelta="100"
         android:toXDelta="20"
         android:toYDelta="100"
         android:duration="2000"
         />
     <!-- 透明度 -->
     <alpha
         android:fromAlpha="1.0"
         android:toAlpha="0.3"
         android:duration="2000"
          />
     <alpha
         android:fromAlpha="0.3"
         android:toAlpha="1.0"
         android:duration="2000"
         />

</set>
     



还没有写onClick所以还不会动-

功能-java档

getDuration()定义影片跑多久

使用switch .. case

package com.huang.myapplication9;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onclick(View view) {
        switch (view.getId()){
            case R.id.button1:
                
                break;
            case R.id.button2:

                break;
            case R.id.button3:

                break;    
        }


    }
}

要先初始化-ImageView

ImageView img =findViewById(R.id.imageView1);

右边做完再到左边

switch (view.getId()){
            case R.id.button1:
                Animation anim1 =AnimationUtils.loadAnimation(this,R.anim.anim01);
                img.startAnimation(anim1);

                break;

https://ithelp.ithome.com.tw/upload/images/20220201/201190351mYN3qePsZ.png


完整程序码:

package com.huang.myapplication9;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onclick(View view) {

        ImageView img =findViewById(R.id.imageView1);

        switch (view.getId()){
            case R.id.button1:
                Animation anim1 =AnimationUtils.loadAnimation(this,R.anim.anim01);
                img.startAnimation(anim1);

                break;
            case R.id.button2:
                Animation anim2 =AnimationUtils.loadAnimation(this,R.anim.anim02);
                img.startAnimation(anim2);

                break;
            case R.id.button3:
                Animation anim3 =AnimationUtils.loadAnimation(this,R.anim.anim03);
                img.startAnimation(anim3);

                break;
        }


    }
}

可以用模拟器测试


BUTTON2的星星与法改这样更美

case R.id.button2:
                ObjectAnimator obj = ObjectAnimator.ofFloat(img, "rotation", 0, 360, 0);
                obj.setDuration(2000);
                obj.start();
                

完整程序码:

package com.huang.myapplication9;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onclick(View view) {

        ImageView img =findViewById(R.id.imageView1);

        switch (view.getId()){
            case R.id.button1:
                Animation anim1 =AnimationUtils.loadAnimation(this,R.anim.anim01);
                img.startAnimation(anim1);

                break;
            case R.id.button2:
                ObjectAnimator obj = ObjectAnimator.ofFloat(img, "rotation", 0, 360, 0);
                obj.setDuration(2000);
                obj.start();

                break;
            case R.id.button3:
                Animation anim3 =AnimationUtils.loadAnimation(this,R.anim.anim03);
                img.startAnimation(anim3);

                break;
        }


    }
}

先全部关掉再做-
https://ithelp.ithome.com.tw/upload/images/20220201/20119035SPr1Hf2BNj.png

从新增模组-从app-new-Module

https://ithelp.ithome.com.tw/upload/images/20220201/20119035hJwNgeWjWB.png

选针对手机+名称
https://ithelp.ithome.com.tw/upload/images/20220201/20119035JABrZtlmtB.png

长出来在-

https://ithelp.ithome.com.tw/upload/images/20220201/20119035h5oAAuQGrT.png

在旁边长出来-
https://ithelp.ithome.com.tw/upload/images/20220201/201190359ySoaV3Rhu.png

用套件做作-套件网址:https://github.com/daimajia/AndroidViewAnimations
https://ithelp.ithome.com.tw/upload/images/20220201/20119035758odLsl2V.png
第一步选Gradle-

https://ithelp.ithome.com.tw/upload/images/20220201/20119035ho2raKy5CW.png

贴上-

implementation 'com.daimajia.androidanimations:library:2.4@aar'

https://ithelp.ithome.com.tw/upload/images/20220201/201190357HzX608jf9.png

要同步载入

https://ithelp.ithome.com.tw/upload/images/20220201/20119035ePscqFvcA6.png


加入两个元件

https://ithelp.ithome.com.tw/upload/images/20220201/20119035JIggH9qYNr.png

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:text="Hello World!"
        android:textColor="?android:attr/colorFocusedHighlight"
        android:textSize="36sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text" />

</androidx.constraintlayout.widget.ConstraintLayout>

改了颜色就会异常消失

https://ithelp.ithome.com.tw/upload/images/20220201/20119035JTwLpxzDgP.png

https://ithelp.ithome.com.tw/upload/images/20220201/20119035jukAvUYB3P.jpg

https://ithelp.ithome.com.tw/upload/images/20220201/20119035cYCYJTbCIM.jpg

https://ithelp.ithome.com.tw/upload/images/20220201/201190356r9zKoNqJb.jpg


直接到JAVA档

1-初始化
https://ithelp.ithome.com.tw/upload/images/20220202/201190352qz1D0nRrI.png

2-加侦听器-onClick是从侦听器加的不是BUTTON的onClick

https://ithelp.ithome.com.tw/upload/images/20220202/20119035BPwZuFn1Gn.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035vFTVYHI8vg.png

package com.huang.myanim2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    Button button;
    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        text = findViewById(R.id.text);
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                
            }
        });
            }
}

再来是Step 2
https://ithelp.ithome.com.tw/upload/images/20220202/20119035EK3p4YugPh.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035rt4nrUBaZj.png

findViewById(R.id.edit_area) 要改成text就是让文字能动

https://ithelp.ithome.com.tw/upload/images/20220202/20119035Zp99NKh0Ov.png

package com.huang.myanim2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;

public class MainActivity extends AppCompatActivity {

    Button button;
    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        text = findViewById(R.id.text);
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                YoYo.with(Techniques.Tada)//要按alt+enter
                        .duration(700)//持续的时间
                        .repeat(5)//重复的次数
                        .playOn(text);

            }
        });
            }
}

然後要换其他效果就是改Tada

YoYo.with(Techniques.Tada)//要按alt+enter.然後要换其他效果就是改Tada
                        .duration(700)//持续的时间
                        .repeat(5)//重复的次数
                        .playOn(text);

这里例如改缩放-ZoomInLeft

https://ithelp.ithome.com.tw/upload/images/20220202/20119035GG7D4XHlO5.png

https://ithelp.ithome.com.tw/upload/images/20220202/20119035yRULWXfzJL.png

YoYo.with(Techniques.ZoomInLeft)//要按alt+enter
                        .duration(700)//持续的时间
                        .repeat(5)//重复的次数
                        .playOn(text);


<<:  企划实现(12)

>>:  企划实现(12)

Vue的简介

Vue的诞生是因为作者尤雨溪希望能同步DOM和JavaScript的物件,在2013年6月他的名字是...

学习Python纪录Day25 - 批次处理档案

批次处理档案 新增多层目录 os.makedirs("./img/a") os....

[Java Day06] 2.1. 阵列

教材网址 https://coding104.blogspot.com/2021/06/java-a...

冒险村16 - customize breadcurmb

延续上篇 customize tooltips with data attribute 後,另外也来...

Day14 - Google Kubernetes Engine 基础 - Deployment 介绍

什麽是 Deployment ? 前几天的教学中我们使用 Pod 加上 Service 在 Kube...