【问题标题】:Press effect Android Widget按下效果 Android Widget
【发布时间】:2014-07-18 00:53:08
【问题描述】:

我想为我的小部件添加按下/触摸效果。我正在尝试类似的东西:

remoteView.setInt(R.id.layout_appwidget_imageButtonPrevious,
                    "setAlpha", 50);
remoteView.setInt(R.id.layout_appwidget_imageButtonPrevious,
                    "setAlpha", 255);

单击 RemoteView 时。问题是效果的发生有一定的延迟,因此只有第二个实际显示在小部件中(因此没有可见的触摸效果)。如果我放弃第二条指令,我会有触摸效果,但它是永久性的,这当然是我不想拥有的。

我该如何解决这个问题?

非常感谢

【问题讨论】:

    标签: android widget touch effect


    【解决方案1】:

    带有动画:

       iv = (ImageView) findViewById(R.id.imageView);
        iv.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
    
                Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
                        R.anim.fade_in);
    
                iv.startAnimation(animFadein);
          });
    

    在 res/anim/fade_in.xml 中

        <?xml version="1.0" encoding="utf-8"?>
        <set xmlns:android="http://schemas.android.com/apk/res/android"
                 android:fillAfter="true" >
    
         <alpha
              android:duration="100"
              android:fromAlpha="0.0"
              android:interpolator="@android:anim/accelerate_interpolator"
              android:toAlpha="1.0" />
         </set>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-25
      • 2018-01-23
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2023-03-31
      相关资源
      最近更新 更多