I've been working on a custom view but am having some serious UI Thread blocking issues when attaching a large number of inflated views to tje custom view (which simply extends a FrameLayout).
While I've tried moving the child view creation from the Main Thread into a background thread, to the point that everything is set up in a thread then a single ViewGroup is added to the activities content view, but the problem with this seems to be that rather than staggering the view laying out and drawing, it is essentially invalidates everything in one go.
Does anyone have any experience of staggering this or have any suggestions how to overcome this issue?
Thanks,
Matt
Can you post more details so that we can understand why the View creation is taking so long?
I don't believe that you can stagger this. Pre-Honeycomb invalidating a ViewGroup caused the entire child hierarchy to re-draw :(
See this great I/O talk for more details.
Related
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.
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 cannot get a view outside the view hierarchy to update it's drawing state. I have a view that i handle the drawing and measuring of as i for a couple of reasons cannot let the container view do this. This works great until i start dealing with views that contain an animation. Even though i repeatedly draw the view it's animation does not change progress. Without knowing that much about the underlying view system i am guessing that this is because animations get updated during traversal of the view tree. because my view is not part of this tree it will not get updated.
The view i am talking about is the "sticky" view in this library https://github.com/emilsjolander/StickyListHeaders
The reason why i handle all drawing of this sticky view myself is because i cannot add i subview to the ListView. Wrapping the ListView together with the sticky view in a FrameLayout has also been tried (fixing this issue but causing other unwanted ones).
So what i want to know is if there is some way to manage all this myself, preferably without the use of reflection. I am also open to suggestions of how to let the underlying view system handle this view!
i have to draw a ball inside a view (or anything else that is good for this task).
I have followed some tutorial about the matter, but every tutorial that i have found
uses only one view (that is shown on the screen without the use of a layout).
But in my Activity i use a layout, that is composed by many views, and i want to draw
only on one of them.
here a little mockup!
Anybody knows a way to do it?
Is the view the wrong container to do it?
Thanks is advance!
Bye
...
You should extend a view that inherits from ViewGroup. this kind of view lets you handle a view that contains other views. with that, you can control the drawing, measures and layout of each of it's children separately
Your mockup can be made with a LinearLayout, which will contain some TextView's and you own View (the one which is containing the ball).
I'm surprised by this question, because there are many examples over the net explaining how to build a layout containing multiple views.
I want to add lazy loading feature to HorizontalScrollView, It has
linearlayout as a child and i am addding to linearlayout,
I am interested in listening to the event when the child view is out
of the visibility area, I see in linearlayout implementation it does
not call either dispatchViewVisibility or onDraw on child view , why i
want that because bitmap attached to the child view can be recycled
and create bitmap again when child view is visible (well that is a
separate part ,How can i create that bitmap very fast, I am planning
to use opengl for that) but the question is how can make such custom
view.
I can not use gallery view because it does not solve my purpose
I saw that viewgroup has feature of dispatchingViewVisibility and
dispatchOnDraw but not sure how to use that with
HorizontalScrollView.?
All i am doing to prevent Out of Memory issue
Any suggestion and help would be appreciated
thanks
Do not use HorizontalScrollView. Instead, use the ViewPager component that was added to the Android Compatibility Library, as it is designed for this sort of scenario. Here is a blog post that explains a bit more.