i have built a custom viewgroup and m beginning to implement animations tot his viewgroup. the problem i am having is that i need the viewgroup to be able to animate without it's children being animated by the same animation.
Lets say i am scaling the viewgroup to 2x size, but i still want to keep children at the same size (thus fitting more children into the viewgroup).
Right now i am calling the animation as follows:
ScaleAnimation expandAnimation = new ScaleAnimation(1,2,1,2);
this.startAnimation(expandAnimation);
Thanks in advance! :)
You can't directly do what you're seeking to do with the old Android animation API. You've already noticed one limitation - that scaling the group also includes the children.
The second limitation is that the old Android animation API only affects the visual render of the item you're animating, and only for the time the animation is active. In other words, it doesn't actually alter the size or positioning of the item in question in terms of view layout. It only temporarily renders it a different way. So for instance, to animate a button moving from x to y across the screen, you would need to run the animation, then when the animation completes actually reposition the button using the layout APIs.
Probably the way to do what you're looking for is:
Incorporate an extra ViewGroup
widget in your layout, positioned
and sized over top the widget
containing the "real" items.
Initially, it's invisible.
Make
it visible, and play the animation.
When animation complete, hide the
extra widget, then resize your real
ViewGroup widget via LayoutParams
and add your extra items.
You'll
probably need to tweak this general
outline to make the effect look
smooth. (For instance, resize the real viewgroup in the background before you remove the fake viewgroup from the screen).
Android introduced a newer, more flexible animation API in 3.0 Honeycomb, but unfortunately it's not available if you're targeting 2.x devices (i.e., phones). Hopefully this will be easier once the new APIs are mainstream.
Related
I'm looking for a way to display views (like buttons, checkboxes, images etc) in a container, which might be bigger than the actual screen size.
A ScrollView within a HorizontalScrollView is no option, since you're only able to scroll one direction at once, not diagonal.
I have yet to find a simple solution to this problem. A zoom function would be nice to have, but that's not as important as the ability to scroll diagonal.
Are there any components out there able to do things like these? Doesn't even have to be for free.
I'm trying to build a point-and-click adventure for Android without using any pre-written engine, but I'm stuck in a really crucial point!
I have a HorizontalScrollView bigger than the screen, so the user can scroll left and right in portrait mode to search around rooms, now what I need is to insert items that the player can use inside this View.
I'm trying to use static ImageView, but I'm really confused on how to insert Views in an absolute position inside the HorizontalScrollView. All I know is that Android manages Views location relative to other views (align on top, next to, bottom of), but what I use if I need to position a View in a specified position using specific coordinates without worrying that the image will be misplaced in a different screen size for other Android devices?
I really am confused on how position views in Android :/
Consider creating your own view instead of abusing HSV.
Custom views, doDraw() method, canvas and even gesture detection is not that hard.
Here is a link that will help you with basics, simple viewport implementation for android with scrolling via key events: http://sonnygill.net/android/android-viewport/
what I use if I need to position a View in a specified position using specific coordinates without worrying that the image will be misplaced in a different screen size for other Android devices
Actually, that's exactly the reason ViewGroup (layouts) were created.
You should choose the right layout based on your requirements.
If you do want to position the views by yourself, you can create your own custom ViewGroup by extending one of the view group classes and override the onLayout(...) and onMeasure(...) methods which are used to position and measure child views (in you case, probably the ImageViews) respectively.
You can use this example of FlowLayout as a reference on how you can write your own custom ViewGroup.
Please note that if your content is bigger than the screen as you mentioned, the HorizontalScrollView should be a parent of a single child (which should be the ViewGroup containing your images).
I have a custom compound view consisting of a textview above an imagebutton (wrapped in LinearLayout). I would like to be able to apply certain gesture-based transformations on it including:
rotating the imageview with two fingers about it's center. TextView stays same orientation
Pinch/zoom to scale the imageview (textview should remain the same size)
move the compound view around the layout
In this scenario there will be several of these views populating a relative/framelayout. The user should be able to interact/modify each view individually.
I've achieved at least a partial implementation for the moving around, based off the answer here: https://stackoverflow.com/a/18806475/2879847. I've read/tried some implementations of the scaling/rotation functions but they seem to apply only to the drawable/bitmap rather than the containing view object so, I'm not sure where to go from there. Any help would be great
Many Thanks - let me know if you guys need any further clarifications.
I've managed to achieve what i want (seems to be working well) - will post some code once my workload dies down.
How can i implement home screen swipe feature of android for a user to swipe between 2 view which covers the entire page. During the swipe the View must animate 100%, but the background must move by only 20%.
I have extensively used: custom scroll view for my app using vertical scroling.
It should be possible to put a bitmap or the like in the background and then when user swipes, manually move/animate the bitmap a factor of 0.20, unless at the edge of the bitmap of course.
Or, as you indicate, having two views. Then you just have to somehow have to, either make the background view ignore user input and let the top view control it, or find a way to pass the input down to the background, having it automatically use a factor 0.20.
Have not tried something similar but believe the link above gives you a lot of control over what is happening.
I was trying to add some buttons to some specific positions on an image. I am making use of webview to display the image because it embeds zoom in/out function; I have tried AbsoluteLayout to put buttons on it but when I zoom in, the button moved..
What should I do then? How can I make the button stick to one position of an image no matter how I zoom in and out?
It seems impossible to get the desired effect if you use WebView, since WebView's scaling does not affect the child view added to it.
If you are working on API 11+, you can use a ViewGroup such as FrameLayout to hold the image and the button, then call View.setScaleX(float sf) and View.setScaleY(float sf) on FrameLayout to scale it, so that all of its child will be scaled too.
I don't have a good solution for API level before 11, since View class does not contain transform information before API 11, maybe you can just recursively adjust the LayoutParams of all the Views to get the effect, I didn't try it, though.