teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

コード修正

2021/09/20 03:31

投稿

jimbe
jimbe

スコア13355

answer CHANGED
@@ -40,8 +40,8 @@
40
40
 
41
41
  TextView text = findViewById(R.id.text);
42
42
 
43
- Button buttonFadeOut = findViewById(R.id.button);
43
+ Button button = findViewById(R.id.button);
44
- buttonFadeOut.setOnClickListener(new View.OnClickListener() {
44
+ button.setOnClickListener(new View.OnClickListener() {
45
45
  public void onClick(View view) {
46
46
 
47
47
  AnimatorSet set = (AnimatorSet)AnimatorInflater.loadAnimator(MainActivity.this, R.animator.flush);

3

コード内不要部分削除

2021/09/20 03:31

投稿

jimbe
jimbe

スコア13355

answer CHANGED
@@ -8,9 +8,7 @@
8
8
  アニメータ(res/animator): flush.xml
9
9
  ```xml
10
10
  <?xml version="1.0" encoding="utf-8"?>
11
- <set xmlns:android="http://schemas.android.com/apk/res/android"
11
+ <set xmlns:android="http://schemas.android.com/apk/res/android">
12
- android:interpolator="@android:anim/decelerate_interpolator"
13
- android:shareInterpolator="true">
14
12
  <objectAnimator
15
13
  android:propertyName="alpha"
16
14
  android:duration="300"

2

リンク化

2021/09/19 17:33

投稿

jimbe
jimbe

スコア13355

answer CHANGED
@@ -1,4 +1,4 @@
1
- <set> タグにおいて android:ordering が使えるのは「プロパティアニメーション」のほうで、<alpha> 等を使う「ビューアニメーション」では使えません。
1
+ <set> タグにおいて android:ordering が使えるのは「[プロパティアニメーション](https://developer.android.com/guide/topics/resources/animation-resource?hl=ja#Property)」のほうで、<alpha> 等を使う「[ビューアニメーション](https://developer.android.com/guide/topics/resources/animation-resource?hl=ja#View)」では使えません。
2
2
 
3
3
  ----
4
4
 

1

コード追加

2021/09/19 17:30

投稿

jimbe
jimbe

スコア13355

answer CHANGED
@@ -1,1 +1,94 @@
1
- <set> タグにおいて android:ordering が使えるのは「プロパティアニメーション」のほうで、<alpha> 等を使う「ビューアニメーション」では使えません。
1
+ <set> タグにおいて android:ordering が使えるのは「プロパティアニメーション」のほうで、<alpha> 等を使う「ビューアニメーション」では使えません。
2
+
3
+ ----
4
+
5
+ プロパティアニメーションで1秒後に点滅するようにしてみました。
6
+ 動作が合っているか分かりませんが、プロパティアニメーションでは repeat 時は startOffset 分の待ちは入らないため、これだけなら android:ordering は必要無さそうです。
7
+
8
+ アニメータ(res/animator): flush.xml
9
+ ```xml
10
+ <?xml version="1.0" encoding="utf-8"?>
11
+ <set xmlns:android="http://schemas.android.com/apk/res/android"
12
+ android:interpolator="@android:anim/decelerate_interpolator"
13
+ android:shareInterpolator="true">
14
+ <objectAnimator
15
+ android:propertyName="alpha"
16
+ android:duration="300"
17
+ android:valueFrom="1.0"
18
+ android:valueTo="0.0"
19
+ android:repeatCount="5"
20
+ android:repeatMode="reverse"
21
+ android:startOffset="1000" />
22
+ </set>
23
+ ```
24
+ MainActivity.java
25
+ ```java
26
+ package com.teratail.q360318;
27
+
28
+ import androidx.appcompat.app.AppCompatActivity;
29
+
30
+ import android.animation.*;
31
+ import android.os.Bundle;
32
+ import android.view.View;
33
+ import android.view.animation.*;
34
+ import android.widget.*;
35
+
36
+ public class MainActivity extends AppCompatActivity {
37
+
38
+ @Override
39
+ protected void onCreate(Bundle savedInstanceState) {
40
+ super.onCreate(savedInstanceState);
41
+ setContentView(R.layout.activity_main);
42
+
43
+ TextView text = findViewById(R.id.text);
44
+
45
+ Button buttonFadeOut = findViewById(R.id.button);
46
+ buttonFadeOut.setOnClickListener(new View.OnClickListener() {
47
+ public void onClick(View view) {
48
+
49
+ AnimatorSet set = (AnimatorSet)AnimatorInflater.loadAnimator(MainActivity.this, R.animator.flush);
50
+ set.setTarget(text);
51
+ set.start();
52
+
53
+ /*
54
+ Animation flush = AnimationUtils.loadAnimation(MainActivity.this, R.anim.flush);
55
+ text.startAnimation(flush);
56
+ */
57
+ }
58
+ });
59
+ }
60
+ }
61
+ ```
62
+ レイアウト: activity_main.xml
63
+ ```xml
64
+ <?xml version="1.0" encoding="utf-8"?>
65
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
66
+ xmlns:app="http://schemas.android.com/apk/res-auto"
67
+ xmlns:tools="http://schemas.android.com/tools"
68
+ android:layout_width="match_parent"
69
+ android:layout_height="match_parent"
70
+ tools:context=".MainActivity">
71
+
72
+ <TextView
73
+ android:id="@+id/text"
74
+ android:layout_width="wrap_content"
75
+ android:layout_height="wrap_content"
76
+ android:text="Hello World!"
77
+ android:textSize="30sp"
78
+ app:layout_constraintBottom_toTopOf="@id/button"
79
+ app:layout_constraintLeft_toLeftOf="parent"
80
+ app:layout_constraintRight_toRightOf="parent"
81
+ app:layout_constraintTop_toTopOf="parent" />
82
+
83
+ <Button
84
+ android:id="@+id/button"
85
+ android:layout_width="wrap_content"
86
+ android:layout_height="wrap_content"
87
+ android:text="animation"
88
+ app:layout_constraintBottom_toBottomOf="parent"
89
+ app:layout_constraintLeft_toLeftOf="parent"
90
+ app:layout_constraintRight_toRightOf="parent"
91
+ app:layout_constraintTop_toBottomOf="@id/text" />
92
+
93
+ </androidx.constraintlayout.widget.ConstraintLayout>
94
+ ```