Shift a image within a Frame in an Android Layout - android

I design a Android Layout where only a cropped part of an Image should be displayed within a frame. I do this with an ImageView within an RelativeLayout. The ImageView lies below the RelativeLayout and is larger than the RelativeLayout. The ImageView is set android:scaleType="centerCrop".
Now I need to shift the Image behind the Frame (the RelativeLayout) in order to display another part of it inside the Frame. How is this possible? A setY() on the ImageView shift the cropped Image, but the Image should first be shifted and cropped afterwards.

Have you tried paddingbottom for imageview?
paddingtop makes image to occupy less height and it gets center cropped in remaining portion
you can align you imageview with relative layout and can show rest of the view

Related

ImageView won't match the parent instead showing white beside the image

I've often seen that I've you place an ImageView in a RelativeLayout in Android, and set its layout:width to match_parent, it won't size the image and make it bigger to fill the width, instead it show some white space besides the image. Why is that happening and how can I handle that?

ImageView which overflows its parent

I have a RelativeLayout which I expand (vertically) when clicked on. This RelativeLayout have a background image. This is implemented by adding a ImageView to the RelativeLayout.
I want the Image (and ImageView) to be larger than the RelativeLayout, so when the RelativeLayout is expanded the background (ImageView) is not stretched but instead just showing a larger crop of ImageView.
I would really like to have a ImageView larger than the RelativeLayout and then just expand the RelativeLayout instead of changing the size of the ImageView when the RelativeLayout is expanded. The reason for this is that the expansion uses a smooth animation and changing the ImageView for each frame leads to a significant overhead since it resizes/crops the image for each frame to match the current size of the RelativeLayout.
Contained Views can't be bigger than their parents.
But the image in an ImageView can be bigger than the View.
Just don't set it as a background (which will be stretched), but as a src.
NO:
android:background="#drawable/my_bg"
YES:
android:src="#drawable/my_bg"
You can play with the scaleType attribute (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html) for fine tuning

Gravity TOP not working when using ScaleType.CENTER_CROP in a ImageView

I have an activity that shows a imageview with a random bitmap from assets folder. I'm loading the image view with this code:
ImageView imv = new ImageView(ctx);
imv.setAdjustViewBounds(true);
imv.setScaleType(ImageView.ScaleType.CENTER_CROP);
imv.setImageBitmap(this.myBitmap);
Also the gravity of the image is set to top of the screen with layout params containing Gravity.TOP
I must use CENTER_CROP because my image sometimes is longer than the height of the screen, and because some other particualirities of my app. I can't use FIT_XY because it deforms my image. I tryed removing center_CROP and did not work, because i want that the image haves the full width of the screen, and without center_crop the image is scaled down.
The problem is that when the bitmap haves more height than the screen height, the image is not starting on the top of the screen, some portion of the upper zone of the image is not being displayed.
How can i avoid that problem?
Thanks

How to scale an Android xml layout while keeping its XML properties?

I've got a framelayout with a 2 pixel border. In the corner of the framelayout, there's a button that the user can drag to resize the layout. I'm doing the resizing by listening to onTouch and calling setScale on the framelayout.
The problem I'm having is that the border and button get skewed when I call setScale on the layout. Is there a way to achieve this resizing effect while keeping the border at 2 pixels and the button inside the layout the same size?

Add ImageView in RelativeLayout with coordinates

How to add ImageView in RelativeLayout with some coordinates, which is bigger than RelativeLayout Size?
Trouble is, when I add ImageView with padding left bigger then layout width, and use in that layout scrollTo(-100,0) (for example), I can't see nothing, my ImageView disappeared, or be smaller(when padding left a little less than layout width).
How can I turn off ImageView auto-scaling or something?

Categories

Resources