【发布时间】:2017-02-06 21:15:49
【问题描述】:
在 Android 中,我尝试在单击图像时淡入和淡出 2 个图像。例如:如果我单击 image1,它会淡出(消失),而 image2 会淡入(我可以看到),当我单击图像 2 时,它会淡出并显示me image1(淡入)。但这里的问题是褪色没有按预期发生。
package com.example.sandeep.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends Activity {
public void fade(View view){
ImageView img1=(ImageView) findViewById(R.id.img1);
ImageView img2=(ImageView) findViewById(R.id.img2);
img1.animate().alpha(0f).setDuration(2000);
img2.animate().alpha(1f).setDuration(2000);
Log.i("Info:","fade method running");
}
public void fade1(View view) {
ImageView img1 = (ImageView) findViewById(R.id.img1);
ImageView img2 = (ImageView) findViewById(R.id.img2);
img2.animate().alpha(0f).setDuration(2000);
img1.animate().alpha(1f).setDuration(2000);
Log.i("Info:","fade1 method running");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
因此,当我单击图像时,只有 fade1() 方法运行,我应该在 dirrenent 屏幕位置上多次单击以使 fade2() 方法运行。在我的控制台中,我得到了下面提到的日志,
02-07 02:29:44.088 10720-10720/com.example.sandeep.myapplication I/Info::
fade1 method running
02-07 02:29:49.728 10720-10720/com.example.sandeep.myapplication I/Info::
fade1 method running
[ 02-07 02:29:50.005 8757: 8757 E/ ]
[adb] handle_packet() t->online(1) p->msg.arg0(23439) p->msg.arg1(0) OPEN
[ 02-07 02:29:50.005 8757: 8757 E/ ]
[adb] handle the adb command, and the command = adb shell:cat
/proc/net/xt_qtaguid/stats | grep 10181
[ 02-07 02:29:50.032 8757: 8757 E/ ]
[adb] cuurent command is A_CLSE
请帮忙解决这个问题。
【问题讨论】:
标签: android android-layout android-animation