I am animating views between two RecyclerView. The first one is something like a list of folders showing the first item as cover, clicking it opens a new view showing the folders content animating the cover to the first item. Clicking back animates all visible views back to the folder where they came from (the cover being the top most view). This looks great as long as the opened folder shows the first item. If I scroll down the first item will be offscreen and the back animation does not look that good anymore because the cover view is not animated (I'm only animating all visible views currently).
What I think would work is following: the LayoutManager could position the first item at a position shortly offscreen and keeps it as a special view in it's pool so that u always can access the first view and when I animate back to the folder view I can animate the cover in addition to all other currently visible items ( the cover will be animated from top of the screen).
This means I need following:
the LayoutManager must handle the first item as a special one that is not recycled (I may need it any time for the back animation)
the first item must always be layed out (either at the default position in the list, if it is visible or offscreen directly above the screen), again because I may need it at any time for the back animation
Can someone help me where to start here? I think this is possible with extending the LayoutManager but I don't know where to start...
Have you tried the following?
recView.getRecycledViewPool().setMaxRecycledViews(TYPE_XXXX, 0);
Trying to create an application where a user drags a view (button/imageView) from a parent layout on top of another layout (probably a framelayout) in a single activity and have it stick to where i dragged it (kind of like a sticker).
The user could repeat this process until the framelayout is filled.
Currently looking at handling onDrag events and on ActionDrop just add a copy of the view being dragged to the new container. Kind of like this except without the removeView method.
Is there a better way? How would i do it if i wanted to place the view being dragged exactly on the same position ontop of the framelayout.
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 a complex frame layout containing several custom views. The main view is a graph.
Overlaying the graph is a custom view which represents a cross hair pointer that the user can drag around the graph to read off detailed information about a particular data point.
The frame layout captures all touch events, calls "hit test" methods on each of it's child views to determine if the touch was on that view then dispatches the touch event to the appropriate view.
When the user touches the cross hair and drags it, I pass the touch event to the cross hair which it uses to update it's position and invalidate itself.
Everything is working except...
All views in the layout are redrawing when I invalidate any of these child views. I know this as I have turned on "show screen updates" in developer options. At no point do I invalidate the containing FrameLayout - or at least, not knowingly.
Certainly, the Activity handling the layout does not invalidate it and I do not have any references to the parent in the child views.
I haven't posted code since a) I don't know if this might be normal behaviour, b) there's a lot of it! and c) if it's not normal behaviour, I don't know which part of the code is problematic. Of course, I'm happy to give anything that might be requested.
My minimum API is 2.3.3 and my target is 4.0. This happens on both of those versions so I suspect my code is the problem but where to start?
Any clues as to what might be going on?
There is no way for View to draw "just itself", since it depends on it's parent (which provides it's clipped and translated Canvas via dispatchDraw method). Invalidation requires whole view tree to be invalidated - this is the answer that you're looking for :)
If you'll check out the source of ViewGroup, you'll find there two important methods: dispatchDraw (which responsible for dispatching draw event down to it's childs) and drawChild (which called by dispatchDraw and let's you specify how childs will be drawn). Note, that there is no check on which View starts invalidation, although there is a RectF that specifies invalidation region. As far as I understand - you need to make sure that your invalidating View (cross) doesn't takes the whole screen, so redrawn will be only that part that it actually takes.
If understand you right, the lines of the cross-hair view cover the whole screen, i.e. one vertical line from top to bottom and one horizontal from left to right.
Now if you change the center of the cross-hair and the other views would not be redrawn, your screen would soon be cluttered with old lines from previous cross-hair positions. You would not want this, so you can be glad that the other views redraw itself too.
If you want, you can specify a 'dirty' rectangle and call invalidate(Rect dirty), which would not redraw Views that are completely outside that rectangle. Though it's up to you in that case, not to change anything outside that rectangle.
try this:
setDrawingCacheEnabled(true);
Enabling drawing cache for view will make view not be redrawn if view not changed
Take a look : Android Invalidate() only single view
May be my answer so simple, but I resolved this problem with help:
this.invalidate()
Run it for each canvas-view, and it will updating one by one (not all at once)
Is it possible to move a ImageView from one layout to another. If i move an image from one layout to another i get an exception "java.lang.IllegalArgumentException: Given view not a child of xyz layout"
If i long press on a application icon, the app is moved from app list view to workspace. How does the launcher do this. How is it able to move the app icon from one layout to another layout ?
I would think of it differently. Instead of moving the actual view object, your layouts should be able to create and remove the same type of view based on the data that the view represents. It sounds like you're doing a regular drag/drop from one layout to another. When the drop occurs in the new layout, this layout should be aware of the data that is dropped and be able to create a new view based on this data. The original layout should be aware that it has lost this data, and remove the original view. Thinking in terms of the data that the view represents instead of the view object itself is probably the way to go here.