ImageView which overflows its parent - android

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

Related

Shift a image within a Frame in an Android Layout

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

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?

CardView vs LinearLayout - images scalling issue

Please look at following 2 layouts.
First, cardview:
http://pastebin.com/iYzUiDQ7
Second, LinearLayout only (layout is actually the same as the one inside my CardView):
http://pastebin.com/xijHZCPw
So, second layout contains WebView component + single LinearLayout under it that should represent the same layout as single CardView item.
It works, however... I'm having problems with scaling images. If I set very large image as image for my ImageView placed on CardView, it will be scaled nicely to fit on my CardView. CardView's height won't be changed, instead, image will be scaled proportionally to fit.
But when I'm trying to do the same with second layout I linked, my LinearLayout changes its height if I set large image. How should I change my second layout to get the same effect for my LinearLayout, placed at bottom of my screen?
I get the difference between the two layout.
you had set the layout_height with 100dp in CardView. so the height of LinearLayout in CardView will does not beyond that. But you set the layout_height with wrap_content in you second LinearLayout.
Try to set maxHeight or layout_height with digit to deal with you problem.
Hope this can help you.

Android scale a RelativeLayout with an ImageView inside

I have a RelativeLayout with an ImageView (with match_parent as height and width). The ImageView has a scaleType of center_crop.
I programatically scale the RelativeLayout in the Y axis according to a specific gesture on the device. The RelativeLayout scales correctly, but the ImageView stretches instead of center_crops as expected. I assume this is because the ImageView is only centered and cropped in the start during the layout process. Is there anyway I can force the ImageView to recalculate the center_cropping process while the gesture is in motion?
I will appreciate any help. I can post more information and examples if my question isn't making any sense.

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