Scrollview making view invisble - android

I have multiple views in my layout inside a ScrollView and there is a validation on certain items, in case of any error I scroll to that view using the following:
view.post(new Runnable() {
#Override
public void run() {
view.scrollTo(0, view.getBottom());
view.getParent().requestChildFocus(view, view);
}
});
But the problem here is as soon as this code runs the scroll is achieved but the view passed to this makes itself invisible. After removing this everything is working fine.
I think this is some sort of bug with scrollview.

Your view is inside scrollView and you have added scrollTo() method in your view not in scrollView. Replace view.scrollTo(0,view.getBottom()) to scrollview.scrollTo(0, view.getBottom()).
Try below solution this might work for you.
view.post(new Runnable() {
#Override
public void run() {
scrollview.scrollTo(0, view.getBottom());
view.getParent().requestChildFocus(view, view);
}
});

Related

Why does smoothScrollTo() not scroll to the bottom?

I'm just wondering what this does.
I've tried using:
scrollView.smoothScrollTo(0, scrollView.bottom)
, but it doesn't even scroll all the way to the bottom...
Thanks
Try to use the code below. It should work for you.
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.smoothScrollTo(0, scrollView.bottom);
}
});
Kotlin:
scrollView.post { scrollView.smoothScrollTo(0, scrollView.bottom) }
Feel free to ask if something is unclear.

scrollview move section to top

I am new to Android Programming. I am using the scroll view for rendering a view.
My XML view as follows:
<ScrollView>
<LL1> <TV1> </LL1>
<LL2> <TV2> </LL2>
<LL3> <TV3> </LL3>
<LL4> <TV4> </LL4>
<LL5> <TV5> </LL5>
<LL6> <TV6> </LL6>
</ScrollView>
When I click on TV6 then LL6 layout should move to the top of the screen.
I tried following things but not working properly:
- TV6.getParent().requestChildFocus(TV6,TV6);
- scrollView.smoothScrollTo(0, 0);
Let me know how to achieve this.
Try this one, maybe this will work for you
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(scrollView.FOCUS_DOWN);
} });
or
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
} });

Android - Scrollview start at the bottom

Is there anyway I can make a Scrollview start on bottom? I tried to:
post(new Runnable() {
#Override
public void run() {
fullScroll(ScrollView.FOCUS_DOWN);
}
});
And also setting the android:focusableInTouchMode="true" on the lowest element in the layout.
But I can see it scrolling to the bottom sometimes. The idea is to make it imperceptible to the user.
Thanks a lot.
try with scrollView.fullScroll(View.FOCUS_DOWN)
Try this
scrollView.scrollTo(0, scrollView.getBottom());
Since I was adding Views dynamically, I also had to allow Android to complete the layout on the content view inside the ScrollView. I just added a post at the end of the View's queue, that will run after it has completed its layout. Otherwise, Android was trying to use the old size of the content view, and wasn't scrolling all the way down.
mMessagesLayout.addView(messageLayout);
mMessagesLayout.requestLayout();
mMessagesLayout.post(new Runnable() {
#Override
public void run() {
mScrollView.scrollTo(0, mScrollView.getBottom());
}
});

scrollTo always works, smoothScrollTo only sometimes

I've subclassed HorizontalScrollView so that I can have some custom scrolling behavior, but have found that smoothScrollTo doesn't always fire.
I've had to work around this problem by using the following code:
smoothScrollTo(x, y);
scrollTo(x, y);
This makes sure the scrolling actually gets done even if smoothScrollTo doesn't work, since scrollTo works every time. Why is this happening? How can I get smoothScrollTo to work every time?
try this:
mScrollView.post(new Runnable() {
#Override
public void run() {
mScrollView.smoothScrollTo(x, y);
}
});
Following code will work:
final int scrollposition = Math.round(hr/24.0f * 1440f);
final ScrollView sv = (ScrollView)findViewById(R.id.graphScrollView);
//sv.smoothScrollTo(0, scrollposition);
sv.post(new Runnable() {
#Override
public void run() {
sv.smoothScrollTo(0, scrollposition);
}
});
Reason:
It will wait for the scrollview to be posted before running the underlying code.

Multi-View Android ScrollView scrollTo Popover not working

My app opens up in View A. In View B, I have made a custom popover who's view contains:
LinearLayout
ScrollView
LinearLayout1
LinearLayout2
.
.
.
LinearLayoutN
What I wish to do is From View A, Move Into View B having set the Vertical Scroll position to a specific LinearLayout from the ScrollView within the Popup.
I have the scrollview being assigned in code to a variable and
variable.scrollTo
is NOT working.
I have also tried to put
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, myNum);
}
});
within the routine I run to setup View B, Tried it Outside in the OnCreate routine. Nothing seems to be working to scroll the ScrollView.
The
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, scrollYPos);
}
});
was EXTREMELY useful, however its placement was even more important. Do to the scrollview being inside of a popover view, the code above actually had to be placed AFTER the code that truly brought that popover onto screen.

Categories

Resources