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 constantsprivatestaticfinalBitmapSOURCE_BITMAP= BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)privatestaticfinalintSTART_X=10;
privatestaticfinalintSTART_Y=15;
privatestaticfinalintWIDTH_PX=100;
privatestaticfinalintHEIGHT_PX=100;
// Crop bitmapBitmapnewBitmap= Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);
// Assign new bitmap to ImageViewImageViewimage= (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:
set android:translationY="300dp" in xml file.
That will move image to bottom side
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"