Animate TextSwitcher, ViewFlipper or ViewSwitcher with children of different heights - android

I want to use a TextSwitcher (or some other switcher with TextViews inside) to animate changing Text.
It should have a sliding animation to slide the old text out to the left and the new one in from the right.
My problem is that when a long text gets replaced by a short text, the TextSwitcher changes its height to a smaller view and the view that is moving out of the screen changes its height too. I want the animated view that is moving out of the screen to keep its height until its gone. Only the new Text should have the new height.
I have
android:measureAllChildren="false"
enabled because my TextView is centered vertically.
I have tried using TextSwitcher, ViewSwitcher and ViewFlipper, but all of these changed the height of the text that was sliding out.

Related

Divide screen to two halves with a title for each and center a view inside each one that will shrink or expand to fill the space

I'm trying to create this kind of layout in android.
I'm using constraint layout. I want to divide the screen with height y to two halves with y/2 height each.
Each one of them will have a textview as title which takes the whole width and has constant height.
And a circular custom view which I would like to expand or shrink so it fills the whole half so the padding marked as 'auto' will all be the same but dynamic.
And p will be a minimum padding that the view can't be over them.
The aspect ratio should of those circles should not be changed.
Is that even possible doing it in the xml design editor? or do I have to do it programmatically.
Next step will be to arrange those halves to be side by side if it's a landscape view.
OK, I did it, Basically you drag the 4 edges of a each view to center it in the outside element. And set the margins to .
So I dragged title2 to all directions of the screen and it got centered. Then I dragged each of the circular views edges the same way so the upper view I dragged to title1 and the bottom to title2. The bottom view I dragged its top to title 2 and the bottom to the bottom of the screen.
Auto resizing is done by setting layout_width to 0 and layout_height 0.

ConstraintLayout alignment with offset

I am using a ConstraintLayout with two views inside. An ImageView that varies in size depending on the image loaded and a View which acts as a custom made dropshadow for the Image. What I've been doing so far is adding 8dp padding to the ImageView and then aligning all of the edges of the View to the ImageViews, thereby making the View stick out 8dp underneath the ImageView.
Now for several reasons I don't want to keep the padding on the ImageView but I still want to achieve the same effect. So basically I would like to align the Left of the View to 8dp left of the Left of the ImageView (and the same for every other edge, right, top, bottom).
Is there any way to achieve this?
Thanks in advance!
I´ve been having problems with this too, it seems ConstraintLayout does not support negative margins yet: https://code.google.com/p/android/issues/detail?id=235306.
In my case, I want a 20dp negative margin to a set of overlapping images on a header image. So far, I'm positioning an empty TextView below the guideline my header image is connected to, with a 20dp top margin and aligning my overlapping image views to that.

use center of view for alignment

I'd like to use the center of a View to align it in another View, let's say, a TextView in a RelativeLayout.
I don't want to have it centered inside the RelativeLayout but rather offset from the bottom left corner.
At the moment I align the TextView ParentLeft and ParentBottom and use margins on left and bottom to move it away from those sides.
However, because my TextView is set to wrap_content in width, it "moves" around when the text inside and with it its width changes (since the borders of the TextView are used for the offsets).
I want the center of the TextView to stay on my offsetted position.
Is this possible in the xml, without having to write code that manages the offset or to use another layout?
That's the unwanted behaviour when the text changes: Screen1
The desirable behaviour: Screen2
Note that the center of the TextView stays the same.
There is a simple logic here. If you want to align a view with respect to the parent then for relative layout you can use align_parent wherein in linear use android:layout_gravity. Here in you case make textview as match_parent and set gravity to centre.

stretch and shrink a row instead of a column

I'm looking to lay out a view similar to how TableLayout works, which can automatically shrink and stretch columns, except I want a row to be stretched and shrunk.
Basically I want to have a fixed-height button (dp) button at the top of the screen, a fixed-height button (dp) at the bottom of the screen, and an ImageView in the middle. I want the ImageView to be stretched or shrunk as needed to accomodate the two fixed-height buttons.
Using a TableLayout with orientation=vertical doesn't seem to do the trick.
Any ideas?
you can use relative layout to do waht you need. Attach the two buttons to the top and buttom respectively. Then for the image you can align its top to the buttom of top button and its buttom to top of buttom button.

How to position a view off-screen so that it can be Animated to move on-screen?

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?

Categories

Resources