In a ViewGroup I want to put two ImageViews overlapping: The imageview A have a transparent background and some drawing across the image, the imageview B.
I want both them to be at the same place and have the same size (but can't fix their size in the XML because if the image at ivB changes the ivA should resize to match the new size.
Since the ivA source image does not change I tried ivA.getWidth() and ivA.getHeight() for setting the ivB size but their value are 0,0 in the onCreate() method.
Is there some "easy" way of doing this?
Override the ImageView and in onLayout() you can get proper width or height after calling super.onLayout(). Try setting values in the place.
Try getting the dimensions in onWindowFocusChangedListener.
An easier way would be putting the ImageViews in a FrameLayout (which is built to put Views on top of the other), and resize the FrameLayout instead.
Related
Is it possible to change an imageview's size after initializing but keep the size the image has after initiliazing? Or is there maybe a way to change an image's size without changing the imageview.
Edit: I need to be able to crop the image from bottom to top without affecting the size of the imageview, so that the bottom part of the image is cut off.
You mist likely looking for android:scaleType of ImageView. See docs.
UPDATE: so i got the picture as a layout:http://gyazo.com/38a4c80dab36e15593a32f35951b9f7d
Now how do i make it so that i can put text on the picture. I want to make sure that the text doesnt go beyond the picture box. Thanks in advance!
Add a RelativeLayout where your picture is now. I suppose your picture has a fixed size (e.g. 60dp wide and 60dp high). Use that size for your RelativeLayout. Now add an ImageView as first child with both width and height set to match_parent. This ImageView will contain your picture. Add a TextView as second child, also with width and height set to match_parent. Now you have a TextView on top of an ImageView, both with the same size.
I'm trying to put corners im my ImageView and I find these "workarounds":
1 - Take the Bitmap soure and paint then
2 - put a second ImageView on my layout and use shape+corners as its source
It's not possible take the image view and put a corner around then?
In my app i have a List with a lot of ImageView (the Bitmap used in this ImageView's is programmatically) and I want to put corners in every ImageView.
There is any other option?
You can create a selector that contains shape with rounded corners, and then apply it as the ImageView's background using xml.
Look at this answers here
You can also do it via code by using PorterDuffXfermode. PorterDuffXfermode uses alpha compositing that will allow you to create and intersection (things of mathematical sets here) between the Canvas you get from onDraw() and an off screen Canvas you will have to create. You will use one of the PorterDuff.Mode flags to tell the framework you want to only render the pixels that intersect from the two Bitmaps in each Canvas.
More on Alpha Compositing
How do I go about setting the background for a splash screen that does not stretch, and maintains a density-independent size? Here's a visual of what I'm trying to go for:
I have a large image file (1000x1000px) of the background. I want the background to maintain its density-independent size, with the excess just not visible, so that it will be displayed correctly on various screen sizes. I also want the center of the image anchored to the center of the screen. (the image above is just a mockup, the focal point should be at the center of the image)
How do I do this?
You have a link here in stackoverflow that might help.
You can use an ImageView as your background (otherwise backgrounds of any view will just stretch).
And use it as the background of your ImageView. Your ImageView can then have the layout_width and the layout_height as wrap_content.
Then, set the ScaleType as android:scaleType="centerCrop".
Note that this ImageView has to be the first element of your layout. Otherwise it will just hide everything in your layout.
I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks
AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.
You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).