Start animation if view is in focus - android

I have a android app and with several Textviews inside linear layyout which is inside scrollview. On a button click I can bring focus and animate any textView (like move left to right). But What I want is, On Scrolling, if a TextView has Focus, animation for this textView should start. Just like this website.
I have an idea, which is: If scroll changes, check textview.hasFocus(), if true then startAnimation. But I don't know which method to use for checking 'if page scrolled'? I don't even know if this is right approach? Please help.

Related

ScrollView does not come back to the beginning of layout - Android

How do I make a ScrollView always come back to the beginning? I have a ScrollView, and inside it a LinearLayout (vertical) with a TextView and a Button called "next". This button changes the TextView text, however the text is not shown at the beginning, but always of where it was visible on screen when the button was clicked. The user then has to scroll to see the beginning of the text.
Is there a way to make the ScrollView go back to the begging when the button is clicked?
Thank you
Just call scrollTo(0,0) on your Scrollview.

Android - Shared Element Transition TextView keeps original layout gravity setting

I'm trying to do a shared element transition with a TextView between an item in a list, and it's detail view.
The transition itself is working correctly, the text and images are moving both to the details fragment, and back to the list to the correct locations.
The problem I'm having is the TextView on the list has left gravity, and the TextView on the detail has center gravity. When the transition happens, it's keeping the left gravity of the original TextView.
It's only after I call requestLayout() in code or click on an actionable item on the screen, that the text centers itself which won't work. I've tried this with and without the onPreDrawListener where you use startPostponedEnterTransition and it's the same problem.
Is there something I need to specifically do so the transition goes to the correct centered location on the detail view immediately?
I don't quite have time to make a sample app of this happening, but I'll have time next week if it's needed. I'm hoping there's just some weird flag that I don't know about and can't find that would resolve this.

Prevent onFocusChanged firing when ScrollView is scrolled

I have a problem where I have several TextView objects in my Activity. More than can fit on the screen view so I have placed them inside a ScrollView.
Now each TextView item is placed into a RelativeLayout before placing onto the ScrollView.
Each RelativeLayout object then has onClickListener and onFocusChangedListeners assigned.
Each Listener implements a method that pops up a dialog to enable the user to edit the value stored by the TextView.
The problem that is occuring is that when the screen is scrolled the onFocusChangedListener event is fired causing the dialog to appear for several items at a time.
Is it possible to detect if the Scrollview is scrolling and prevent the onFocusedChanged event firing?
I can post code if required but its quite large as the items added to the page are done so dynamically. This also means there is no xml for the layout.
I looked at using the ScrollView onTouchListener to add a flag ignoreFocusChange but it appears this would not work as the event was hit sveral times for one swipe/fling on the screen.
Please help
Regards,
Iain
After spending some time on this I found that the best solution for me was to remove the onFocusChangedListener and replace it with onTouchListener

How to make an activity scroll to a certain point?

Is it possible to have an activity scroll down to a certain point when a button is clicked?
I want my activity to behave just like an anchor in a web page.
I have two buttons at the top of the activity, followed by lengthy text aboout each of the buttons. When I click on the button at the top I want the page to scroll down beginning of that button's description.
Is this possible?
Assuming you are using a TextView to display your text, you use the built in scrolling function myTextView.scrollTo(x,y). Put it inside your buttons' onClicks and you should be good to go!
http://developer.android.com/reference/android/widget/TextView.html
So your outer layout is a scroll view?
You can call
View.requestFocus()
Obviously, the view has to be focusable.
The problem with scrollTo(x,y) mentioned above is most likely that you don't know x, y.

Vertical smooth scrolling of values in a text view

I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!

Categories

Resources