Imageview on-touch/click 效果无多重效果 (Android)
Imageview on-touch/click effect without multiple effects (Android)
有没有在imageview按下时显示某种效果。我使用 imageview 作为按钮,所以需要显示一些触摸效果。许多现有线程提出了具有多个图像的选择器。这是太多的工作,因为我有很多 imageviews。我也愿意扩展 imageview class。任何想法或解决方法。
在点击函数中添加
ImageView img= (ImageView) view.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
在Assets中创建一个anim
文件夹,然后清理一个名为alpha
的动画资源文件
在文件中粘贴以下内容
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="50"
android:fromAlpha="0.5"
android:toAlpha="1.0" />
这种类型的动画只是将 Alpha 透明度设置为 50%,然后再设置回 100%,这样图像就会闪烁。
有很多动画,所以在网上四处看看,找到你喜欢的那个,然后创建动画资源文件,把名字放在这里R.anim.alpha);
在您的 imageView xml 文件中您可以添加 android:onClick="myClickFunction"
然后在activity中添加
public void myClickFunction(View v) {
ImageView img = (ImageView) v.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
}
有没有在imageview按下时显示某种效果。我使用 imageview 作为按钮,所以需要显示一些触摸效果。许多现有线程提出了具有多个图像的选择器。这是太多的工作,因为我有很多 imageviews。我也愿意扩展 imageview class。任何想法或解决方法。
在点击函数中添加
ImageView img= (ImageView) view.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
在Assets中创建一个anim
文件夹,然后清理一个名为alpha
在文件中粘贴以下内容
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="50"
android:fromAlpha="0.5"
android:toAlpha="1.0" />
这种类型的动画只是将 Alpha 透明度设置为 50%,然后再设置回 100%,这样图像就会闪烁。
有很多动画,所以在网上四处看看,找到你喜欢的那个,然后创建动画资源文件,把名字放在这里R.anim.alpha);
在您的 imageView xml 文件中您可以添加 android:onClick="myClickFunction"
然后在activity中添加
public void myClickFunction(View v) {
ImageView img = (ImageView) v.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
}