我希望點擊效果時,點擊圖像,但從我的代碼,每當我第一次單擊圖像沒有發生,但是當我第二次點擊它顯示橙色影響被點擊的效果。下面是我的代碼,我知道這可能不是這樣做的正確方法。但我想知道爲什麼發生這種情況它需要雙擊點擊效果onClick按鈕()
image.xml
<ImageView
style="@style/icon"
android:background="@drawable/fear_96"
android:onClick="see"
android:id="@+id/abulation"
/>
下面
是的onclick方法
public void see(View view) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
view.getBackground().setColorFilter(0xf0f47521,
PorterDuff.Mode.SRC_ATOP);
view.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
view.getBackground().clearColorFilter();
view.invalidate();
startActivity(view.getId());
break;
}
return true;
}
});
}
public void startActivity(int id)
{
Intent intent=new Intent(this,DuwaListView.class);
switch (id)
{
case R.id.abulation:
intent.putExtra(Intent.EXTRA_TEXT,"Abulation");
break;
case R.id.dressing:
intent.putExtra(Intent.EXTRA_TEXT,"Dressing");
break;
case R.id.restroom:
intent.putExtra(Intent.EXTRA_TEXT,"Restroom");
break;
default:
Toast.makeText(this,"underconstruction",Toast.LENGTH_SHORT).show();
return;
}
startActivity(intent);
}
請幫助爲什麼這個代碼表明這種行爲
只需使用_AlphaAnimation_或_ObjectAnimator_ – Piyush
我的問題是爲什麼它顯示這樣的行爲?我知道還有其他方法可以做到這一點。請在簡單地投票之前閱讀我的問題的最後一行 – FaisalAhmed