如何以编程方式在 imageView 图像下添加橙色线?

发布于 2024-11-28 07:27:07 字数 1210 浏览 2 评论 0原文

如何在图像显示在图库中之前在图像下方添加橙色线?
我想标记图片,使其从其他图片中脱颖而出。

我已经测试了各种 LayoutParams 但需要建议。
请参阅大量解释如何仅在 xml 中执行此操作。
这是适配器中我的 getView

(如果有人需要,请更新工作解决方案)
imageViewWithLine 是具有布尔值的自定义 imageView
决定是否应该画线

public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null){

       BitmapFactory.Options bf = new BitmapFactory.Options();
       bf.inSampleSize = 8; 
       Bitmap bitmap = BitmapFactory.decodeFile(files.get(position).getImagePath(),bf);
       ImageViewWithLine imageViewWithLine = new ImageViewWithLine(ctx, null);
       BitmapDrawable b = new BitmapDrawable(getResources(),bitmap);
       imageViewWithLine.setLayoutParams(new Gallery.LayoutParams(80, 70));
       imageViewWithLine.setScaleType(ImageView.ScaleType.FIT_XY);
       imageViewWithLine.setBackgroundResource(GalItemBg);
       imageViewWithLine.setBackgroundDrawable(b);
       convertView = imageViewWithLine;

    }

    if(files.get(position).addLine() == true){
       ((ImageViewWithLine)convertView).setLine(true);
    }else
    ((ImageViewWithLine)convertView).setLine(false);

    return convertView;

    }
}

How do i add an orange line under the image before it's showed in the gallery?
I want to mark the picture so it sticks out from all the other.

I have tested all kinds of LayoutParams but need advice.
See loots of explanations how to do this in the xml only.
here is my getView in the adapter

(UPDATE WITH WORKING SOLUTION IF ANYONE NEED IT)
The imageViewWithLine is the custom imageView that has a boolean
to determent if line should be drawn or not

public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null){

       BitmapFactory.Options bf = new BitmapFactory.Options();
       bf.inSampleSize = 8; 
       Bitmap bitmap = BitmapFactory.decodeFile(files.get(position).getImagePath(),bf);
       ImageViewWithLine imageViewWithLine = new ImageViewWithLine(ctx, null);
       BitmapDrawable b = new BitmapDrawable(getResources(),bitmap);
       imageViewWithLine.setLayoutParams(new Gallery.LayoutParams(80, 70));
       imageViewWithLine.setScaleType(ImageView.ScaleType.FIT_XY);
       imageViewWithLine.setBackgroundResource(GalItemBg);
       imageViewWithLine.setBackgroundDrawable(b);
       convertView = imageViewWithLine;

    }

    if(files.get(position).addLine() == true){
       ((ImageViewWithLine)convertView).setLine(true);
    }else
    ((ImageViewWithLine)convertView).setLine(false);

    return convertView;

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧笙踏歌 2024-12-05 07:27:07

您可以扩展 ImageView 类并创建自定义视图。在自定义视图中,您可以覆盖 onDraw 并以这种方式绘制橙色线。

更新:

这只是一个普通按钮,底部有一个橙色条。尺寸并不准确,但它应该为您提供一个良好的起点。

public class ButtonWithLine extends Button {

    public ButtonWithLine(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.rgb(255, 125, 0));
        paint.setStyle(Paint.Style.FILL);

        float height = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());

        canvas.drawRect(0, getHeight() - height, getWidth(), getHeight(), paint);

        super.onDraw(canvas);
    }
}

You can extend the ImageView class and create a custom view. In the custom view you can override the onDraw and draw your orange line that way.

Update:

This is just a normal button, with an orange bar along the bottom of it. The dimensions aren't exact, but it should give you a good starting point.

public class ButtonWithLine extends Button {

    public ButtonWithLine(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.rgb(255, 125, 0));
        paint.setStyle(Paint.Style.FILL);

        float height = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());

        canvas.drawRect(0, getHeight() - height, getWidth(), getHeight(), paint);

        super.onDraw(canvas);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文