タイトルの通りですが、
以下のようにテキストとボタンの2つだけを設置し、
テキストがフェードアウトするアニメーションを定義したつもりなのですが、
ボタンを押しても一瞬点滅するだけで期待する動作になりません。
何が間違っているのでしょうか。
activity_main.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:id="@+id/container" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:orientation="vertical" 9 android:layout_marginTop="100dp" 10 > 11 12 <TextView 13 android:id="@+id/childview" 14 android:layout_width="match_parent" 15 android:layout_height="50dp" 16 android:orientation="vertical" 17 android:text="child view here!!" 18 android:fontFamily= "sans-serif-light" 19 android:textSize="30sp" 20 android:textColor="#e2f2f8" 21 android:gravity="center" 22 android:background="#17abe1"/> 23 24 <Button android:id="@+id/button" 25 android:layout_width="fill_parent" 26 android:layout_height="wrap_content" 27 android:text="Button" /> 28 29</LinearLayout>
motion.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:interpolator="@android:anim/accelerate_interpolator"> 4 <alpha 5 android:fromAlpha="1.0" 6 android:toAlpha="0.0" 7 android:duration="10000" /> 8</set> 9コード
MainActivity.java
java
1 Button button = (Button)findViewById(R.id.button); 2 button.setOnClickListener(new View.OnClickListener() { 3 @Override 4 public void onClick(View v) { 5 TextView text = (TextView) findViewById(R.id.childview); 6 Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.motion); 7 text.startAnimation(animation); 8 } 9 });
◆補足
実行環境
Android 7.1.1
「アニメーションが動かない」なので同じ原因の可能性がかなり高いですよ。片方解決で両方解決かと。事前の状態の違いで問題は同じです。
https://teratail.com/questions/102487 これと重複しているとおっしゃっているのでしょうか?102487で求めている回答は「一般的なアニメーション方法の手段」であり、本件で求めている回答は「前提となるソースがある状態での間違いの指摘」です。重複ではありません。