Android scale a RelativeLayout with an ImageView inside - android

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.

Related

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

How to use scaletype of a ImageView as center and matrix at the sametime?

Is there a way to set the ScaleType of a ImageView as CENTER using Matrix ScaleType?
I'm in need of Center orientation of an image in the ImageView. Problem occurs when I set the size of the ImageView larger than the screen say 1000dp. By doing so my image sticks to the corners.
If I use layout_margins, I'm not able to pinch and zoom the image properly.
Please help me find a solution.

Bitmap ImageView, inside a HorizontalScrollView. How to fit the HorizontalScrollView Height with the bitmap?

I have a Horizontal Scroll View, and inside it i have a ImageView. This imageview has a Bitmap with high width and low height.
I want the bitmap to fill the height of the horizontal scrollview, and I want to scroll the bitmap from left to right.
I tried to use this code, but it doesn't work. It creates two spaces on left and right, these spaces are black. These spaces are from the ImageView... so... the bitmap has less width than the ImageView
HorizontalScrollView wvScroll = new HorizontalScrollView(this);
wvScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
iv.setImageBitmap(Util.getRemoteImage("http://mywebsite.com/90.gif"));
//iv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
iv.setScaleType(ScaleType.CENTER_INSIDE);
iv.setBackgroundColor(Color.BLACK);
wvScroll.addView(iv);
wvScroll.setBackgroundColor(Color.GREEN);
mainLayout.addView(wvScroll);
what am i doing wrong? I also tryed with iv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); but it doesn't works, Same result.
EDIT:
I also tryed with ScaleType.CENTER_CROP and it doesn't works fine. The bitmap has higher height than the ImageView, because some pixels lost on top and bottom of the bitmap.
If I had to approach this in the simplest way. I'd set the width of the scroll view the same as the screen width. The height doesn't matter as much because you're assuming the height will fit in the screen(At least that's what I gather from your question).
From what I remember scroll-views will scroll anything bigger than than the actual screen or anything that is bigger than the specified scroll-width or scroll-height its given.
This might help you get started with getting the respectable screen sizes - Get Screen width and height
Of course since different devices have different screen sizes - you'd have to do this "pro-grammatically".
Would this sort of implementation work for you?

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?

How to resize a ScrollView

I have a ScaleDetector in which I zom in my ImageView when it detect a scale movement.
This works, the image is well scaled.
But the problems is that my ImageView is in a ScrollView, and the ScrollView doesn't resized itself when I scale. So when my imageView is scaled, I can move on it in the first limits of my ScrollView, not beyond.
And of course, the SrollView doestn't have an "setMatrix" or something like that which could allow me to easilly resized it.
So how can I do to resize my ScrollView ?
First solution I can think of is, in your java code insert :
scroller = (ScrollView) this.findViewById(R.id.scroller);
scroller.setLayoutParams(new LinearLayout.LayoutParams(width, height));
Then adjust width and height according to your scale.

Categories

Resources