I have a layout where I have to take an ImageView, and position it somewhere relative to something in the background image. For instance, the ImageView would be of an item, and on the background image there would be a shelf, and I would need to position the ImageView such that the item looks like it is on the shelf. Another example would be of a frame in the background, and I would need to position the image so it looks like it is in the frame. This needs to account for scaling. I do not need it to work through rotation, as there are different layouts for portrait and landscape.
One way would be to associate the relative position of these items with the background images themselves. For instance, the height of the position of the top of the table is at x% of the total height of the image. Then, when it scales, it's now at x% of the current height.
Related
I currently have a recycler view that has a list of CardViews.
When I click on the card I want to be able to expand the card (change only the height). This is working fine by setting the new height to the card with an animation.
The problem is that when I click to expand the card, the width also shrinks to less than half the width of the screen. If I scroll the view away and come back the width is set correctly. Every time I try to expand the height, it expands to the right size but the width shrinks.
Is there something that I'm supposed to do to expand/collapse a card in a recycler view and not have this side effect of also resizing the card width?
I tried only setting the height in a valueAnimator and that works for the expansion.
I tried to set the width programmatically at the end of the animation to match parent but that has no effect.
for better solution pls share code with us, until that.
check your xml codes for any Wrap content value for width.
It will solve your issue.
I have total 5 image views in linear layout.first round it shows only 3 image views centre of the layout and second round first 3 image views are scale down or translate and visible the 4th image view and centre of the partent. and third round 4 views are scale down and visible the 5th image view in centre of the parent.
How to achive this in android using animations?
Animations can be performed through either XML or android code. Here you get animation using xml.
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
Hope it helps !
I'm trying to place a small image on the top of a big one in a custom dialog.
I want the small one to be placed in a different place depending on a variable, which I called "pos". It contains a int value from 0 to 100, meaning percentage of the dialog width.
If pos = 0, I want to place the image in the left margin of the big one, if pos = 30 it should be placed in the 30% of the screen, starting from the left.
If pos = 50 I want it to able placed right in the middle, being 100 the maximum value for it and placing it in the right margin.
I include a draft to explain myself a bit better.
I tried with RelativeLayout.LayoutParams but I never get expected output.
Perhaps a simpler strategy is to extend ImageView, then create a custom image using Canvas commands in the onDraw method that draw the bitmap appropriately on the x axis with a background set to match your layout.
You can determine the width of the custom dialog in the the onMeasure method of your custom ImageView, so the returned bitmap (including empty background) can be the correct width, and the position of the smaller bitmap can be correctly apportioned.
Once you've created the class, which will take just a few minutes, you can add it to your XML layout with something like:
<com.domain.yourapp.YourCustomerImageView
android:id="#+id/bitmap_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"/>
i have 2 imageview. first one for containing the image and the other one as the frame.
i already set image position to have the same position as the frame after loading the image.
i also already check the value and its the same.
but somehow the image position is not the same as the frame when i try changing picture with 2 different size (width x height).
ivProfilePicture.setX(ivFrame.getX());
ivProfilePicture.setY(ivFrame.getY());
by the way, i use custom imageview for the image container, i only custom the function onMeasure. there's no image repositioning.
I have a RelativeLayout filling the screen and a couple of ImageView positioned on it using LayoutParams margins. These ImageView are animated in different ways, and in one case I want an image to "fly in" to the screen from the right.
Unfortunately, if I set leftMargin for that ImageView greater than the width of the screen, it does not appear (or appears cropped if it partially visible at the start of animation).
I tried setting width and height of RelativeLayout to be bigger than screen size - it works, but only partially: if the image is positioned completely off-screen, it does not work, and if the image is partially visible, it is not cropped, but that works only for right and bottom sides.
So, my question is this: how to position several ImageViews on and off the screen so that I can animate them using Animation?
In the end, I used a trick: I combined AnimationDrawable and view animation. I did the following (assuming that the animation has to run T milliseconds):
Position that ImageView on-screen.
Set as its background an AnimationDrawable with following frames:
empty Drawable: 1ms,
normal Drawable: Tms.
Change view's animation to this:
jump to off-screen position (translation with duration=1ms),
do normal animation.
This is probably a good place to start looking for those who would use Fixpoint's solution.
Android — How to position View off-screen?