I have a LinearLayout that, throughout the course of the application, aggregates child views that can be removed. My question is, when a child is removed from a parent view, is there any way to animate the other children into place? In essence, I want to sort of recreate the effect of the ICS/Jelly Bean recent apps window - when one is swiped away the others sort of fall into place. I know that this specific implementation is made by Google and thus is probably outside the realm of possibilities that I can do, but how would I go about emulating that effect?
Thanks!!
Read about viewgroup animation in this answer. You can use animation API to create animation.
https://stackoverflow.com/a/6524820/940680
Related
Whenever a new view is added or removed, everything is adjusted. I can see how in majority of use-cases this is a very good thing, but unfortunately for me, it's something I need to avoid. I'm assuming that onMeasure() is called whenever a view is removed or added, resulting in it changing the X and Y coordinates I gave it, however I want to "disable" this.
My app utilizes dynamically moving and resizing views, determined by the user at runtime, hence if whenever the user removes a view or adds a new one, it shifts everything around, it'd be extremely annoying. Also I'd think that (although not sure) that preventing this could only help performance right? Not measuring each view, in fact, I do not want it to measure it at all because, once again, the user decides the view size and location, not the linear layout.
I was thinking of creating my own ViewGroup, but I've never done this before. I know you can extend a pre-existing one, like LinearLayout or RelativeLayout, but I need help determining which one I should use, and whether or not I should just create a full on ViewGroup.
As I said, it doesn't need to measure the views at all, and in fact, if it were possible, a container that does nothing would be optimal, and I'd think would yield more performance. Can anyone help me with this problem?
Summary:
Need a way to either prevent a pre-existing ViewGroup, I.E FrameLayout, RelativeLayout and LinearLayout, that do not adjust the position nor size of the view, or create a new ViewGroup which doesn't do any measuring at all because the user defines the location and size at runtime and should not be altered by the container.
If this is a bad question or another question exists that answers this, please let me know.
I am introducing view object recycling into my Android app to help performance. It does help with that. But when a new screen appears, I am seeing brief artifacts which I assume are related to the prior state of the views. The artifacts take the form of a rectangular region of some color that should not be there. The app adjusts itself to the correct state very quickly, but it's still annoying. I am wondering if there is a way to prevent this. What I am currently doing is removing the old view from the hierarchy and un-setting its event handlers. Obviously, that is not enough. LayoutParams typically relate a view to its parent; perhaps I need to be somehow "un-laying-out" the view when removing it? But I'm not sure how to do that.
If your performance issues lay in a ListView, you can use RecyclerView instead to help that: https://developer.android.com/training/material/lists-cards.html.
Besides that, how exactly are you recycling and what type of Views do you use?
I am new to android therefore I got a little bit lost with all those ViewFlipper, ViewSwitcher, ViewAnimator and ViewPager. Moreover, I am not sure what's happening under the hood.
Basically I have an activity which shows some data. With swipe (or button, doesnt matter) I would like to scroll the view and get to another page (as seen in the picture below).
Is it possible to implement something like that without changing to another activity?
I am a little bit confused regarding views and access to the design elements. How those pages are located each to another? e.g. If I am currently seeing Page1, can I modify content of Page3? Or plainly saying, are all page views loaded all together? As if I set setContentView(R.layout.xlayout); then I can access only xlayout elements.
But if I use same activity, then I have a thread there which updates a counter on Page1, if I change view to Page 2, the counter will not find Page1 Counter TextView and will complain.
As I Understand Android 4.0 has ViewPager which is similar to the seen in the picture. I am using GB. Should I use support library or can I just go around and implement something similar without importing any libraries?
(Sorry, my description is a little bit messy)
Yes, you can use ViewSwitcher, ViewFlipper and ImageSwitcher depending on your requirements.
ViewSwitcher may have two childs at max. And these child might be a View or an object of subclass of view.
ViewFlipper: May have as many childs you want. and these child might be a View or an object of subclass of view.
ImageSwitcher might be used to switch images over.
By using view flipper you can display one item at a time, and adding a gesture overlay, you can apply sliding effect. To apply View Flipper, you need to add all the views to ViewFlipper, and showNext and showPrevious methods are used to show next and previous child.
You need to use a ViewPager to have the same behaviour as in Google Play.
it only available on recent version of Android, but you can use the Compatibility Package to make it available for older version.
With a ViewFlipper you can't "scroll" between two pages.
I've just started playing with Android in the last few days and have begun to put together a simple application. I am struggling to work out whether I'm doing things the "right" way or just making life difficult for myself.
The app displays a series of connected nodes on the screen, similar to a mind-map. I want to be able to tap the nodes in order to edit them. When the map of nodes becomes larger than the screen, I need to be able to scroll on both X and Y axes as needed to see the whole map. Image of current implementation at http://ubergeek.org.uk/images/nodetest.png.
Currently I don't have scrolling working, however I assume that I can do that by making the root view a ScrollView and sticking an AbsoluteLayout inside that (though it's deprecated, I wish to place objects at specific X/Y coordinates).
The nodes themselves are currently each a pair of roundrects (one for the outline and one for the fill) and a drawText and are being drawn in the main activity's onDraw(). In order to make these clickable buttons I believe I need to create a custom view for the button in order to use its onClick() events. I can then create a view object for each of my nodes and add them to the AbsoluteLayout view.
Does this sound like a reasonable way to do it in Android, or is this a horrible abuse of the API? :)
Thanks!
Nope, that sounds about right. You just need to make sure that the view contained by the ScrollView has the right dimensions so the scrollbars will show up right, but I'm sure you got that covered.
It's certainly a bit non-standard, but I'm tempted to say that your approach will work right... I'd even go so far as to say that it's not a hack. Please keep us posted on how it works out, and if anything breaks!
(Btw, the SDK mentions that you should write your own layout instead of using AbsoluteLayout. Personally, I'd say use the AbsoluteLayout.)
Let me start out by saying that I feel like there should be a very simple way to do this, and it's entirely possible I'm missing something very simple. But all the examples I find for transition animations (push left out, push right in, etc.) deal with moving from one view to another. What about an application that only has one view, but dynamically changes the data feeding that view?
The best common example of this is the base calendar app. It has identical views, but when you swipe forward or backward the date of the view transitions with a swipe animation.
How do I reproduce this? Surely I don't have to inflate ViewFlippers for the same view? And if so, what is the best way to go about this?
Thanks in advance.
The source code for Android can be found on source.android.com, and the project for the Calendar application can be found here.
From the looks of things, they use a ViewSwitcher to process the animations, triggering an animation based on a fling gesture. It's rather complicated, which is why this is on my list of reusable components to write one of these days...
A kind of hacky way of doing this would be to set the layoutAnimation of your view (in XML or Java) and simply remove the view from your window, then edit the data, then re-insert it in to the window again. This will call a layoutAnimation to happen. Note however that with this implementation you can't do remove animations.
You could also use the standard animation framework to transform the view off the screen. Once it has finished that, edit the data of the view. Once that is finished, set another animation on the view to slide back in again.