Prevent ScrollView from scrolling to top - android

I've a ScrollView, inside that there are few views one of them is a TextView. I'm pragmatically setting current time to the TextView. Therefore TextView updates every second. Now when I over scroll ScrollView, the ScrollView moves to top. I guess its losing touch when TextView updates.
So how can I prevent ScrollView to move to top?

That's your friend:
android:descendantFocusability="blocksDescendants"
Set this attribute to the Elements INSIDE of the ScrollView.
But since this removes the focusability of the elements you won't be able to edit any inputs like EditText etc.
In this case you could "prevent" the ScrollView from scrolling to the current focus (it does not scroll "to the top") by ensuring the focus to be at the position I like.
To give an example:
I've got a ScrollView with a TableView inside and a CheckBox in each row of the table. When I check one of them, the color of the current row is to be changed. But: the moment I set the color, the ScrollView scrolls to the focus.
So I set the focus to the ckeckbox I just clicked before I change the color:
// enable focusability if necessary:
// cbOK.setFocusable(true);
// cbOK.setFocusableInTouchMode(true);
cbOK.requestFocus();
row.setBackgroundColor(....);

Related

Change focus in RecyclerView in single vertical click

I am building an app for Android TV by using Nested RecyclerView. Root is vertical RecyclerView which has rows with Horizontal RecyclerView.
I want to change the focus on the single click and want to keep the scroll position static. But scrolling is always happening at the bottom of the view for horizontal and vertical both.
I am using the focus listener to scroll to top
verticalRLVLayout.scrollToPositionWithOffset(rowNumber,0);
horizantalRLVLayout.scrollToPositionWithOffset(columnNumber, 0);
This is not working always and i don't see this is the best option.
Is there any way by which if we have fixed height of each row the single click will change the focus always.
Going upward in the RecyclerView, causes new row to slide towards right and focus goes to last visible tile on the previous row. Why this is happening, any idea ?
Thanks

ScrollView childrens loses focus when scroll

I have a listview and button in a scrollview. When i scroll both list and button loses focus. When i tap on button it did not work but next time i tap it works i think button loses focus and focus is towards scrollview how to handle this please help
Never put ListView inside a ScrollView. ListView handles scrolling, and wrapping it in a ScrollView can cause problems with focus, touch-events etc. If you want other Views added to the top or bottom of you list, simply use ListView.addHeaderView() or ListView.addFooterView()
Scroll view can have only one child, put your button and listview in common layout and try out.

android edittext and textview scroll together

I have a edittext and textview next to each other. I'd like, when I scroll with the edittext(either with finger or by adding new content to edittext) that the textview scroll the same distance. I've tried querying the getScrollY
I am not sure if I understand your question perfectly, but if I do, then I would suggest putting these two elements side by side in a Horizontal linear layout within a Scroll View. This way if / when either of the elements are moved, they will stay with each other.

Prevent ScrollView to focus on child elements during scrolling?

I have a ScrollView in which I have a quite long form, mainly using EditText elements. The problem is, that when the user scrolls around in this form, ScrollView changes the focus constantly. It seemed to me, that it assigns focus to the first element on screen when the user stops touching the screen, and the fling motion triggers.
How can I disable this?
Just a thought that you can make EditText as non-focusable elements. And when user will click on any item in ListView you can make that particular element focusable again.

How to focus child item while finger slipping on its parent container like a Linearlayout?

I have a LinearLayout which contains some TextView vertically. I have made all TextView focusable.
What I want to do is that when user use finger slip on the LinearLayout from top to Bottom, the focus would change accordingly, the focus should change along with finger movement.
How can I do this?
There is no focus when the user's finger is on screen. See http://android-developers.blogspot.com/2008/12/touch-mode.html

Categories

Resources