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;

    }
}
4

1 回答 1

2

您可以扩展 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);
    }
}
于 2011-08-05T19:36:06.833 回答