Custom viewgroup with animated view - android

I made a custom viewgroup, and I need to use view animation to rotate some views...
But they are misbehaving, no matter if I put the startanimation inside onDraw, onLayout or onMeasure, my views flicker (you see them briefly rotated, and then briefly non-rotated, and that pattern repeats).
How I fix that?

see Android transfer animation of view in custom viewgroup and Animating Views
view.animate().rotation(180);

Does your animations work properly in a non-custom viewgroup?
I tried to use a custom ViewGroup in order to create an animated background, however, just like you, I had some strange behaviour. I solved it by simply using a FrameLayout and inserted two fill_parent views: a custom one and a LinearLayout. Then the LinearLayout which came on top of my custom view was working as expected.

Related

Is it possible to enable touch events for a View inside a ViewGroup but outside its bounds?

I'm currently trying to design a ViewGroup (specifically a subclass of FrameLayout) that can layout any number of subviews and enable them for drag/drop outside the layout group. It's almost identical to a LinearLayout:
Curently I am able to drag the views outside the ViewGroup and draw them, however after letting go of the view it can't be re-selected and further dragged around.
I'm wondering if there is a way to do this in a way that isolates the logic to the Layout subclass and doesn't involve needing to do much/any extra stuff in consuming fragments/view groups.
I've tried overriding getHitRect(Rect) in my FrameLayout subclass but it never seems to be called. dispatchTouchEvent(MotionEvent) is of course not called either, presumably because the parent ViewGroup has decided not to deliver the touch to it because it was outside the bounds. I've tried implementing a TouchDelegate as well, but I think that needs to be set on the parent view, which means needing to know about this and doing this additional step when using this Layout.
Any ideas on if/how this is possible? On iOS it can be implemented fairly easily by overriding hitTest: to take into account the frames of the child views. Is there a similar method like this on Android?
Your help is greatly appreciated!
Without any code it is very hard to see what you are doing, but best guess would be that each view should a child view of the relative layout.

Implementing custom scrollable arc (circullar) viewGroup

I have been working with Android for about 4 months. I need some guidance on how to implement something like this:
In that picture I've used three of the custom viewGroups (calling it ArcScrollView) stacked on top of on another which is what I am trying to achieve.
The questions that I have are:
Do I need to extend ViewGroup, frameLayout or what?
How can I make it scrollable?
I took a look at LinearLayout source code and it was extending frameLayout but again LinearLayout is not scrollable and need to be hosted by a scrollView.
I need to have complete control over scrolling because these arcScrollView are rectangles and I need onTouchIntercept of the viewGroup to return false (not consuming) at certain positions.
Is scrolling actually just changing the starting position of the first child view and putting them after one another or something magical that Android does?
I think I need to override the onDraw method also for drawing the partial circle. Does that effect anything that I need to worry about?
Should I override the ScrollView and LinearLayout instead? because I think there is a lot that have been implemented in them.

Is it safe to draw a view that was not added to the view group using addView?

I am trying to draw a View in a ViewGroup without adding it to the child list.
I am doing this because I want to display something like a ProgressBar in the exact center of layouts like a LinearLayout so I don't want the layout to handle the measuring and layouting.
I also don't want to complicate the view hierarchy by adding extra layouts just to achieve this effect so my solution was to extend the LinearLayout, create a ProgressBar and handle measuring, layouting and drawing for that view myself.
My implementation seems to work ok from what I tested but I am wondering if there is anything I am not noticing or if there are any problems that can appear in the future.
From what I understand calling addView also sets the child view's parent and calls dispatchAttachedToWindow, these methods are package-private so I can't call them myself.
Is there any side effect that can arise from calling measure, layout and draw on a view that has no parent and that was not "attached" to a window? Is there a safer way to achieve the same effect?
Thanks.

Android GLSurfaceView as subview

I'm very new to an Android platform and currently trying figure out why things work this way:
If I create GLSurfaceView and add it using the setContentView or addContentView to an activity everything works fine (Renderer.onDrawFrame is called as expected). However if I add my GLSurfaceView to another ViewGroup (which is then added using setContentView) nothing is rendered.
So what is the difference between addView and addContentView ?
In the end I need to create a custom view with OpenGL rendering in background and some controls on top.
Also what is the point of separating View and ViewGroup? Why not to join them (like it is done in CocoaTouch) ?
setContentView(View) sets the parent View for an Activity (or dialog etc...).
addView(View) adds a View to a ViewGroup.
View and ViewGroup are mostly different. View is a more specific single entity. It should be used more on one facet of what you are trying to do. ViewGroup, however, focuses more on the whole and acts (is) a container and layout organizer for a collection of Views.
Can you post all the code related to the GLSurfaceView and how you are setting it as contentView?

Animating a ViewGroup without animating child views

I have been having a lot of trouble lately trying to get my custom ViewGroup to animate (scale/translate animation) independently it's child views. Worth noting is that my custom ViewGroup is visible and not just a container, thus the need to animate it and not only it's children.
I want my ViewGroup to have 2 states, unexpanded and expanded with the former being able to display 1 view and the later being able to display that view in addition to 4 more (total 5).
The animation my ViewGroup uses to enter/exit the expanded state is done and i am very happy with it. Though when adding a View into the ViewGroup it to will expand with the same animation as my ViewGroup which i definitely do not want.
Ok, that was a lot of explaining (hope you understood half of it) but now comes what i want to achieve. I want to control my ViewGroup with one animator and all the child Views with another independent animator.
I have a feeling i am going at this the wrong way so if anyone has something easier/better to suggest than please do.
Thanks!
I solved my problem by using a ValueAnimator and animating the LayoutParams of my ViewGroup :)

Categories

Resources