1

I am trying to give some slope in ImageView. Is it possible to do? If so then how?

Below image display exactly what i want to do. I have highlighted slope in ImageView.

enter image description here

Thanks for any kind of help

Darsh Patel
  • 1,015
  • 9
  • 15

3 Answers3

2

What you're trying to achieve can be done in a couple of ways.

First method - use an overlay image

This is probably the most straight-forward method to implement this. Create a bitmap, or a drawable which is essentially a triangle with the desired background color (dark red in your example), and give it to an ImageView which is placed over your original ImageView, aligned to the bottom. This new ImageView will basically block out the bottom part of your original ImageView, giving you the desired effect.

Second method - use image masks

This method is slightly more complex, but will remove the need for having an additional ImageView in the layout. Basically, it means you'll need to process the bitmap a bit before setting it on the ImageView, and you'll need an additional bitmap which defines the shape of the resulting image. This bitmap will be the "mask" of your image. Click here to see an example on how to do this.

Community
  • 1
  • 1
Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
  • Thanks for answer. It's working fine !!! but one remark is that we need to create mask image. We can't use normal image as a mask image. – Darsh Patel Mar 29 '16 at 11:33
  • You can mask your image from below link : http://www166.lunapic.com/editor/?action=mask – Darsh Patel Mar 29 '16 at 11:36
0

Try this, with API > 11

mImageView.setRotation(angle);

with API>=11

You can also set it from xml

android:rotation="90"
Raghu Nagaraju
  • 3,278
  • 1
  • 18
  • 25
0

You can extend ImageView and override onDraw method like this:

Paint paint=new Paint();
paint.setColor(Color.BLACK);
@Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);            
            Path p=new Path();
            //start from bottom left corner
            p.moveTo(0,canvas.getHeight());
            //move to the offset
            p.lineTo(canvas.getWidth(),YOUR_OFFSET);
            //move to bottom right corner
            p.lineTo(canvas.getWidth(),canvas.getHeight());
            //return to bottom left corner
            p.lineTo(0,canvas.getHeight());
            //clsoe the path
            p.close();
            canvas.drawPath(p,paint);
        }

that in case you want to paint the region with some color.

otherwise, you can define the clipped region and use canvas.clipPath(Path path) method

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158