0

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;

    }
}
Erik
  • 5,039
  • 10
  • 63
  • 119

1 Answers1

2

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);
    }
}
zeonic
  • 383
  • 3
  • 9
  • It's working but i must scroll the gallery out-of-view and back again to get the line to show. If i have 100 images in the gallery it's not efficient to redrawe all just to get one image-line to show. Is there a way to tell gallery to reload only on image or something – Erik Aug 05 '11 at 20:40
  • I updated my question, love to see a solution how to make gallery update selected view only – Erik Aug 05 '11 at 21:52
  • got it working now by calling invalidate() on the custom imageview. Thanks @zeonic – Erik Aug 06 '11 at 08:08