About add Customized View - android

I want add customized View to ScrollView. In customized View, Only two methods are described, constructor and onDraw(). But the image that drew in onDraw(), isn't show on ScrollView. What's wrong in my program?

You might need to override onMeasure() so the view can be sized appropriately. Otherwise it might help if you post some code with your question.

Related

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.

Difference between onMeasure, onLayout, OnGlobalLayoutListener

I am doing a very simple feature like adding ellipsis at the end of a TextView.
I could add the feature in onMeasure(), onLayout() and OnGlobalLayoutListener() call. But I really wanna know what's the difference by implementing the same functionality but in these three different method.
Are there any preferences or pros and cons for choosing these different implementation ways?
Thank you
Try to follow this it will help
The layout process consists of two passes, measuring and layouting. A
bit simplified we can say that the measure pass sets how big the view
should be, the dimensions of it, and that the layout pass sets where
to place the view, the position of it. The layout part is only
interesting for views with children, in other words views that
inherits from ViewGroup.

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 animation behind other views

Developing for android I need a translate animation. That was easy, but I want the animation to go behind the other views. How can I achieve that?
setZAdjustment(Animation.ZORDER_BOTTOM) does not work. It cannot be that hard...
I had the same problem in a RelativeLayout with an animated ImageView.
Defining/adding my animated View in the first place in/to the RelativeLayout and then the other views helped me.
How I solved this problem was to implement my own android.view.animation.Animation class, and overrride the applyTransformation() method. From this method I set a few of my own custom drawing variables, (X offset, etc.) and then called invalidate() on the view being animated. Note that my view as a custom view and I had all my drawing done in onDraw.

Rendering absolutely positioned sprites over a regular Android layout

I've got a standard RelativeLayout laying out my Buttons and TextAreas. What I want to do now is be able to draw various sparks, flying cows etc. at arbitrary places on the screen on top of the whole thing. What's the best way to do this? Should I override onDraw() on the containing View and draw after calling super.onDraw()? Or is there some better way of drawing a layer on top?
You'll probably want to put your Relative layout and a custom view which isn't focusable and doesn't consume motionevents inside a FrameLayout, then override OnDraw in that custom view. That way you can call invalidate() on that view without making Android redraw everything else.

Categories

Resources