How to force start animation if view out of window - android

I have a scroll view with several views and only one view can be expanded. When another view gets expanded the already expanded view gets shrunk. But the animation for the not visible item on the screen gets started only when the view gets visible.
So is there a way to force start the animation?
Setting the height for not visible item causes unwanted jumping of scroll Y if the view is on top and view on bottom gets expanded.

I had the exact same problem and was so happy, that i found the question on SO, only to find out that no one had answered it. I looked around for a solution but didnt really find one. So what i did in the end was to check if the item was in the visible area (was pretty easy for me, since i used a custom pager) and set the animation time on the invisible items to 0.
Worked for me, but i dont know if this will work/worked for you.
PS: I would have posted a comment instead of an answer but i think i am not allowed yet.

Since nobody knowing this, I must assume this cannot be done.

You just invalidate the invisible view by invalidate() method.

Related

RecyclerView remove animation bug

I have implemented a RecyclerView where I can add and delete items. I want the added item to be added on the second last position and, whenever I add a new item, the animation runs well. That is, the last item moves downwards, letting space for the new item to fade in.
When I remove an item there is a problem that I don't know how to fix. How I want it to behave is:
fade out the deleted element,
move upwards all the items below it.
What actually happens is that, first thing, the last item disappears, and then the rest of the animation takes place. When the items below the deleted element move upwards, the last item reappears as coming from behind a wall.
To me it seems as if the RecyclerView shrinks to the "post-animation" height, and then the animation is performed.
I haven't defined the ItemAnimator, so the DefaultItemAnimator must be the one used. I have watched this video, and overridden the supportsPredictiveItemAnimations method in a custom implementation of LinearLayoutManager, but it doesn't fix it.
I already reported the problem through Google Issue Tracker here
I hope we can get a fix soon! As you say It seems very related to a possible race condition between the measure updates for the recyclerview and the animation when your recyclerview is wrapping it's content to calculate it's height.
This article explains the problem in a really detailed way also.
Perhaps a bit late, but I was able to fix this in my situation by setting the RecyclerView item animator to null, and then in the setList(list) function of my Adapter scheduling a Transition as such:
Transition transition = new AutoTransition();
transition.setDuration(200); // Or any duration you want
TransitionManager.beginDelayedTransition(mRootViewGroup, transition);
where mRootViewGroup is the viewgroup containing the RecyclerView.
This problem is also fixed by setting your layout_height (or width, depending on the scrolling orientation) to something other than wrap_content, but if, like me, you need your recyclerview height set to wrap_content, this might be a solution for you.
Not certain it will fix your problem as well, but I figured I might as well share what worked for me.

Android: Invisible objects still clickable

I have an activity that has buttons and images that can appear and disappear depending on user interactions.
What I am finding is that objects at the back, which have been set to invisible, are still triggering clicks, sort of. They are not processing the code related to being clicked, but they sort of momentarily reappear, and then disappear again instantly when clicked on.
They also appear to be interfering somewhat with buttons laid over the top of them. These buttons become very fiddly and difficult to click at times, when there is an invisible object behind them.
I am using simply:
object.setVisibility(View.VISIBLE);
And:
object.setVisibility(View.INVISIBLE);
To make my items appear and disappear. Is this not what I should be doing?
EDIT:
People keep asking me for the exact same code that they are giving me. This is the code I have been given, and that I am using currently.
btnLifePlus5.setVisibility(View.GONE);
btnLifePlus5.setFocusableInTouchMode(false);
txtLifePlus5.setVisibility(View.GONE);
txtLifePlus5.setFocusableInTouchMode(false);
btnLifePlus1.setVisibility(View.GONE);
btnLifePlus1.setFocusableInTouchMode(false);
txtLifePlus1.setVisibility(View.GONE);
txtLifePlus1.setFocusableInTouchMode(false);
btnLifeMinus5.setVisibility(View.GONE);
btnLifeMinus5.setFocusableInTouchMode(false);
txtLifeMinus5.setVisibility(View.GONE);
txtLifeMinus5.setFocusableInTouchMode(false);
btnLifeMinus1.setVisibility(View.GONE);
btnLifeMinus1.setFocusableInTouchMode(false);
txtLifeMinus1.setVisibility(View.GONE);
txtLifeMinus1.setFocusableInTouchMode(false);
This makes no difference to just setting them as invisible.
Making any View invisible don't prevent us to trigger their listeners. It's just you can not see it every other thing would be same as if it was visible.
If you don't want to use it at all change it to View.GONE
Difference in View.INVISIBLE and View.GONE: Invisible objects keep on utilizing the space assigned to it while object set as View.GONE would leave the space of space as if its not on screen.
Use
object.setVisibility(View.GONE);
rather than
object.setVisibility(View.INVISIBLE);
Use object.setVisibility(View.GONE); instead object.setVisibility(View.INVISIBLE);
View.GONE Means This view is invisible, and it doesn't take any space for layout purposes.
View.GONE This view is invisible, and it doesn't take any space for
layout purposes.
View.INVISIBLE This view is invisible, but it still takes up space for
layout purposes.
I hope it will helps you .
Try:
object.setClickable(false);
As an alternative, you can:
object.setEnabled(false);
The only way I managed to solve this ridiculous issue was to create a sort of view panel that sits between the objects in my activity. This view panel is the size of the screen, uses the same colour background, and starts invisible.
Normally, I make object A disappear, and make object B appear. When I click the space previously occupied by object A, it momentarily flashes back onto the screen and then disappears again. It looks terrible. Subsequent clicks do not reproduce this bug until the next time I make object A disappear.
The fix is to make object A disappear, make the new view panel visible on top of it, and then make object B appear on top of the view panel. So the panel acts as a sort of barrier between the hidden object, and user interactions. The user is not aware that this view panel even exists, as it blends in to the standard background, but when I now click the space where object A would be, it now no longer flashes back onto the screen momentarily. While this is a poor solution to have to use, this OS is bugged and I am left with no choice.
My activity now looks as though it is perfectly stable and working perfectly. I don't like it, but it works.
Thanks a lot, google.
Try object.setVisibility(View.GONE)
View.GONE prevents view to draw its layout bounds (width and height) whereas View.INVISIBLE draws it.
You should use:
object.setVisibility(View.GONE);
View.GONE removes your view completely from the layout, but View.INVISIBLE only makes your view invisible but still found in your layout, thus clickable.
In my case, I was animating a layout and then set it hidden.
However, I was using View.GONE but still, the layout views were taking clicks.
Then I found that in the animation I was using anim.setFillAfter = true
changing it to "False" fixed the clicks issue for me.
Hope it helps someone banging their head.

Android, what happens to Listview if IME pops up?

I have a listview inside a fragment. When IME pops up the listview is resized, but I want to know what happens in code behind for that listview. As for what I have observed the listview's notifydatasetchanged() method is not called because it will refresh the listview but this is not the state here. The only thing I see is that the view of the list item is updated not the whole listview.
Could anyone clarify whats happening to the listview?
Thank you.
If you have adjustResize as your softInputMode, the entire window is resized, causing a relayout to happen. Any scrollable containers are adjusted so that the focused view is visible. If you have adjustPan, the window is only moved, but not resized.
None of this has anything to do with data. In fact, in both cases the view doesn't even need to requery the adapter since either its size is getting smaller (it will discard views), or its size will be exactly the same, just off screen.
What are you trying to achieve that you're asking this question?

TabHost inside a ScrollView forces it it to scroll to the bottom

My question is very similar to this unanswered one, with some small differences that I will explain:
TabHost inside of a Scrollview: always scrolls down when a Tab is clicked
My ScrollView initiates scrolled to the bottom, showing the TabHost content instead of the ones on top of it (you can see the screenshots in the linked question, it's very similar).
If I manually scroll up, clicking in different tabs doesn't affect the ScrollView, the problem is only in the first time it's shown. This is the difference between the other question.
Things I tried with no success:
Make the top components inside the ScrollView focusable, so they would get the focus instead of the tab.
Force the ScrollView to scroll to the top in onResume() method with sv.fullScroll(View.FOCUS_UP); or sv.scrollTo(0, 0);. Also, no luck in the initialization, but subsequent calls to onResume() effectively scrolls it to the top.
Any ideas on why this is happening? Tips on how to further investigate are also very welcome.
Probably too late to help you Pedro, but I did figure out a solution that worked for me. I noticed in the TabHost source that it requests Focus if nothing else in the view has focus. So I made sure that the first component in the Scroll view was focusable and requested focus for it.
// Get the first component and make sure it is focusable. Note you have to use setFocusableInTouchMode and not setFocusable for this to work.
TextView v = (TextView) view.findViewById(R.id.first_component_in_view);
v.setFocusableInTouchMode(true);
v.requestFocus();
Hopefully this will help someone.
I have a similar problem and haven't solved it. However, to force the scroll view to scroll you need to update it's progress through a separate thread to post on the UI. e.g.
quickScroll.post(new Runnable() {
#Override
public void run() {
quickScroll.scrollTo(0, 54);
}
});
Where quickScroll is my ScrollView. I believe the reason for this is that you have diagrammatically defined your layout, or inflated it from a custom viewgroup. So setContentView doesn't hold a reference to the scrollView, so you have to force the UI to update off the variable allocated to the ScrollView.

Scrolling issues with GridView in Android

I am having weird scrolling issues in my pretty simple GridView. Each item in the Grid is simply an ImageView and a TextView. The activity itself is simply an application selector. It looks like a rough version of the basic App Tray in Android.
The issue is that after spending some times scrolling through my view, it will inevitably allow me to continue scrolling past the top row of icons, to a blank screen, and the scroll bar will disappear, leaving me stuck.
It doesn't happen every time I go to the top of the view, only sometimes, and usually only after some excessive scrolling.
If I happen to notice the problem and catch it before the top row disappears off the bottom of the screen, I can usually scroll back through the view and spot some icons missing. There are empty spaces in the grid, and I can only assume that those icons have been moved to some bizarre position, which is allowing the view to scroll past the top.
This is my first Android app beyond a basic Hello World, so it's likely that I've just screwed up something in my layout files. I also realize that this is probably a pretty confusing description, so I'm hoping someone has experienced this and my search abilities simply were unable to find it.
I can post my layout files or other code if someone thinks that's useful.
Oh, and the program is built against 1.5, but is running on 2.2 (whatever state of 2.2 that was that snuck out last week) on my phone. I don't have enough apps to test this on an emulator, but could probably set something up if someone felt it necessary.
Thanks in advance for any help on the issue.
I had same problem, but I post to GridView only ImageView's so pengwang's answer didn't help me. I found explanation for this bug https://code.google.com/p/android/issues/detail?id=16218
The problem is that GridView does not currently handle items with differing heights.
My solution is to use exactly specified layout_height same for all GridView's items.
i have solved it: in the link GridView cannot show image you can try
It seems that if you scroll off the bottom of the GridView and back again very fast a couple of times, you eventually will notice that the elements of the view get shifted one place to the "left" from where they originally were. When this happens, you then can scroll all the way off the top of the GridView. When you do reach the top of the list, item 0 is not displayed, having item 1 in its place and nothing but blackness above that row.
Clicking on any item in this situation resets the list and everything is back to normal.
This must be a bug. It's highly reproducible, and I don't think anything I'm doing is causing the mix up. At this point, adding to the list adapter has stopped.
Right now I'm working with Android 2.3.3.
I just ran into this exact same issue myself -- I have a grid of images that have different heights. After reading the Android developer's doc on GridView, GridView.LayoutParams and GridLayout, I did two things that fix my issue:
find the tallest image in each row, and store the height in a map of row -> rowHeight. Each image that I download has width and height info, so this is easy for me to do by overriding my adapter's addAll(items) method.
in getView(), I create a GridView.LayoutParams(MATCH_PARENT, getRowHeight(position)), which sets each grid item to the max row height for its specific row.
wrap my ImageView inside a LinearLayout. I have tried other layout but LinearLayout is the one that works. Set android:scaleType="fitCenter" and android:adjustViewBounds="true" for the image view.
After above 3 steps I finally got the grid to look right, they have different heights, and there's no scrolling issues.
I had a similar, but probably less common problem, where just scrolling a little bit would scroll the gridview to the end and I was not able to scroll up at all. This only occurred when the gridview was smaller, for example when the keyboard was visible. The problem was that I used:
android:paddingBottom="400dp"
android:clipToPadding="false"
Making padding bottom much smaller fixed my issue. I hope this helps at least someone!

Categories

Resources