Skip to content Skip to sidebar Skip to footer

Display Half Of The Image At The Bottom Of The Screen

My requirement is to display half of a wheel image at bottom of the screen. I can't cut the image, as I need to rotate it at run time. I have tried different options with relative

Solution 1:

You could always crop the piece that you need via the Bitmap.createBitmap() static method, and then assign it to the view:

Something like...

// Set some constants
private static final Bitmap SOURCE_BITMAP = BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)
private static final int START_X = 10;
private static final int START_Y = 15;
private static final int WIDTH_PX = 100;
private static final int HEIGHT_PX = 100;

// Crop bitmap
Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);

// Assign new bitmap to ImageView
ImageView image = (ImageView)findViewById(R.id.image_view);
image.setImageBitmap(newBitmap);

In here, your SOURCE_BITMAP is your original steering image.

I hope, this helps.


Solution 2:


Solution 3:

First set imageview align bottom in relative layout in xml file. Then set imageview margin programmatically by half (or ratio you want) of imageview height.

int height = imageview.getHeight();
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(0, height/2, 0, 0);
        imageview.setLayoutParams(params);

Post a Comment for "Display Half Of The Image At The Bottom Of The Screen"