【问题标题】:Imageview on-touch/click effect without multiple effects (Android)没有多重效果的 Imageview 触摸/点击效果(Android)
【发布时间】:2015-10-06 04:15:24
【问题描述】:

按下 imageview 时是否可以显示某种效果。我使用 imageview 作为按钮,所以需要在触摸时显示一些效果。许多现有线程提出了具有多个图像的选择器。这工作量太大了,因为我有很多图像视图。我也愿意扩展 imageview 类。任何想法或解决方法。

【问题讨论】:

  • 你看过ImageButton类吗?
  • 谢谢大家。 Imagebutton 不好,因为我在自定义标题栏上使用它。 @saree,你已经指定了一种方式,我必须为每个图像视图使用选择器。我喜欢karan sugession。但我一直在寻找发光效果或一些动画。
  • 那么你在自定义标题栏上使用这个做什么?

标签: android imageview


【解决方案1】:

在点击函数中添加

 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);   
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 2012-08-22
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    相关资源
    最近更新 更多