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
.
Thanks for any kind of help
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
.
Thanks for any kind of help
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.
Try this, with API > 11
mImageView.setRotation(angle);
with API>=11
You can also set it from xml
android:rotation="90"
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