I have a LinearLayout which contains several views. When I add a new view to the linearlayout programmatically, I want it to fade out the last view on the right, and to move in the new view from the top (translateY). What is the best way to implement this intro/exit transition that works from API 14+?
Related
I need to use a custom view in order to show an animation. Right now I have a layout with a button, and when that button is pressed, the custom view is set and the animation starts inmediately. The problem is that the button should be on top of the custom view so the user can see the view before the animation starts.
I have searched and I think it can be done by using a FrameLayout, but I don't know how to implement a custom view inside a FrameLayout. Can anybody help me?
Make a Layout with the stuff you want inside the FrameLayout such as a LinearLayout, Relative, etc..
Inflate that Layout using a inflater and them place the layout on your FrameLayout
Or you can inflate your customView and add the view to it.
View myCustonView = (View) inflater.inflate(R.layout.mycustomview);
myCustomView.addView(myButton);
I am working in android 2.3 and I have an issue which is a bit of a pain.
I have 2 layouts on top of each other in a FrameLayout. The top layout is moved partly off-screen during an animation, and the .layout() method is called in the animation end. This works great and the ui is moved correctly and the buttons of the toplayout is still clickable.
After the animation the second layout is visible as the toplayout is moved off-screen. This layout contains a list which is clickable and each cell has an ImageView which is updated when clicked. However my problem is, when the table cell is clicked and the ImageView is updated, the entire view is reset, ignorering the animation and new location of the toplayout. It just sets the toplayout back on top as the animation never happend.
I use an TranslateAnimation and the set fillafter is set to true as well.
Do you guys have any suggestions to what I might be missing.
I guess your problem is placing objects inside FrameLayout. As described in this answer you cannot place a view inside a FrameLayout by setting its location.
It's true that with FrameLayout all children are pegged to the top
left of the screen, but you still have some control with setting their
padding. If you set different padding values to different children,
they will show up at different places in the FrameLayout.
Use padding instead to "move" the view off-screen.
I have a view animator that I am adding images to dynamically via a web service call. However, the scroll bar refuses to show up no matter how many pics I add to the ViewAnimator. Thoughts?
The ViewAnimator is not a scrollable layout. Adding a childview to view animator will not show the added view if you don't have a mechanism to call showNext or showPrevious.
Maybe you want to use a ScrollView instead? You nee to create a ScrollView that contains a LinearLayout with a vertical orientation. You can now add images dynamically to the LinearLayout and the ScrollView will increase in size.
I understand that View overlapping has been addressed for background images with components on top. However, what if I had the following, where the image from a button overlaps another view, outside of its container?
Example 1
View are not allowed to overlapped in LinearLayouts. It is used to arange child views in either vertical or horizontal manner. When views are bigger than its parent, it renders in the bounds of its parent and the rest is cut of.
You can stack child views on top of each other by using the framelayout. But from seeing your buttun, I think you can achieve it using a Relative layout. And telling the arrow to stay below button using layout_below attribute.
Let me explain the scenario that I want to achieve:-
Consider the below as the Layout I have inside a Parent_Linearlayout:
[Linear Layout] (Fill_Parent, Wrap_Content)
[ScrollView]
Activity's setContentView is set to the Parent_Linearlayout
In the application, when a condition is met, I want the Scrollview to be removed from the screen and instead put another View in its place.
I've been able to do this, & when I remove the ScrollView, I'm applying translate Animation to it so that it seems as if the View has gone to the top -before removing it.
But when the animation occurs, the ScrollView translates OVER the Linear layout present above it.
How do I restrict it, so that the scrollview does not go over the linear layout, but disappears at the base of the Linearlayout. I want the linearlayout to always stay visible..
I've been trying to do this from quite some time, but I've not been able to get desired results..
Could someone kindly help me out here??
I don't quite understand your description of your layout, but the Android view system is drawn based on the ordering of the views in the hierarchy. Views added later to a parent are drawn after those added earlier. So if you always want the LinearLayout to be drawn on top of the ScrollView if/when they overlap, then declare or add the ScrollView object to its parent before the LinearLayout object.
In thinking more about this, I suppose the ordering here is important because you want the ScrollView to be placed below the LinearLayout in the parent of both of these views. Putting the ScrollView first (and thus having it painted first) would then put it above the other LinearLayout, which isn't what you want.
There are various ways to achieve what you want. For example, you could use a RelativeLayout as the parent of the views, then the ordering is not important.
Alternatively, you could place the ScrollView inside another LinearLayout (and that LinearLayout would be the second child of the overall parent layout). Then when you animate the ScrollView, it would be clipped by its immediate parent, which I believe would give you the effect you're looking for (make sure that setClipChildren() is set to true on this new intermediate LinearLayout, which it is by default, otherwise it won't clip the ScrollView as it animates out of it). Note that this approach would necessitate different animation values, since you are now animating the view outside of its parent (the new LinearLayout).