tags:

views:

45

answers:

2

I have an ImageView in my android layout. And I would like to add a 'decorator' image at the lower right corner of my image view. Can you tell me how can I do it?

I am thinking of doing with a FramLayout with 2 image views as its child, but how can i make one image the lower right corner of another?

<FrameLayout>
   <ImageView .../>
   <ImageView .../>
</FrameLayout>
+2  A: 

You probably want to be using a RelativeLayout (Documentation) instead - it supports stacking views, and all you'd have to do is align the bottom and left of the overlay ImageView with the bottom and left.

QRohlf
So is this method better or creating my own ImageView?
michael
It depends on what you're trying to do. The method Fedor describes is slightly more resource-friendly and scalable, so if you're going to be doing this to hundreds of images or something you probably want his method. The method I describe is simpler to implement in XML and basic layout code.
QRohlf
A: 

You could create your own class that extends ImageView. It will always draw decorator over the ImageView content.

public class MyImage extends ImageView {

    static Bitmap decorator;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(decorator==null)
            decorator = BitmapFactory.decodeResource(getResources(), R.drawable.decorator);
        canvas.drawBitmap(bitmap, 0, 0, null);
    }

    public MyImage(Context context) {
        super(context);
    }

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

    public MyImage(Context context, AttributeSet attrs, int params) {
        super(context, attrs, params); 
    }
}
Fedor