【问题标题】:How to highlight a Bitmap? Like Google Play如何突出显示位图?喜欢谷歌播放
【发布时间】:2012-12-21 07:45:27
【问题描述】:

如何突出显示位图?就像 Google play。

我的图片在服务器中,所以我想下载两张图片来制作这种效果。

我尝试过的:

我只是尝试使用图层,但它不会产生透明的高光效果。 位图设置在Imagebutton

也许画布应该可以工作,用浅色创建可绘制透明,我尝试了一些代码但不起作用,或者因为我不知道如何处理这个问题。

BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);

                    Drawable[] layers = new Drawable[2];
                    layers[0] = bitmapDrawable;
                    layers[1] = r.getDrawable(R.drawable.default_button_pressed);
                    LayerDrawable layerDrawable = new LayerDrawable(layers);
                    imageView.setImageDrawable(layerDrawable);

default_button_pressed

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle">
    <corners android:radius="3dp" />
    <gradient android:endColor="#FFFFFF" android:startColor="#ccffff" android:angle="90" />
    <stroke android:width="1dp" android:color="#33364252" />

</shape>

【问题讨论】:

  • 我建议发布您使用层的代码,并更改您的问题以寻求有关您遇到的特定问题的帮助。
  • 你能给我们提供一个高亮和常用位图的例子吗?更容易理解你想要什么。
  • 我只是更新了 Google play 中的示例以及我尝试过的内容。
  • 我在这里可能是错的,但我不认为这实际上是突出显示位图,而是在 GridView 中加载图像并在选择项目时对其应用样式。如果你这样做,它会默认“突出显示”它

标签: android bitmap android-canvas highlight


【解决方案1】:

尝试使用ColorFilter:

Imagebutton.setColorFilter(0x808fd2ea);

【讨论】:

    【解决方案2】:

    使用OnTouchListener 和使用ImageButtonsetColourFilter 方法很容易

      ImageButton aButton = (ImageButton) findViewById(R.id.MY_IMAGEBUTTON_ID);
       aButton.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent me) {
                ImageButton button = (ImageButton)v;
                if (me.getAction() == MotionEvent.ACTION_DOWN) {
                    button.setColorFilter(Color.BLUE);
                    return true;
                } else if (me.getAction() == MotionEvent.ACTION_UP) {
                    button.setColorFilter(null);
                    return true;
                }
                return false;
            }
    
        });
    

    【讨论】:

    • 它可以正常工作,但不是这种颜色,我使用了来自@vmironov 的颜色代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2018-08-18
    • 2012-08-23
    • 2018-12-03
    相关资源
    最近更新 更多