How to scroll to bottom in a ScrollView on activity startup
It needs to be done as following:
getScrollView().post(new Runnable() {
@Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
This way the view is first updated and then scrolls to the "new" bottom.
Android: ScrollView force to bottom
scroll.fullScroll(View.FOCUS_DOWN)
also should work.
Put this in a scroll.Post(Runnable run)
Kotlin Code
scrollView.post {
scrollView.fullScroll(View.FOCUS_DOWN)
}
How do I make ScrollView auto scroll to the bottom?
Try below code to achieve your task :-
scroll.fullScroll(View.FOCUS_DOWN);
or
ScrollView sv = (ScrollView)findViewById(R.id.scrl);
sv.scrollTo(0, sv.getBottom());
Android Studio automatic scroll to bottom when ScrollView expands?
For automatically scrolling to add the code:
final ScrollView scrollview = ((ScrollView) findViewById(R.id.scrollview));
scrollview.post(new Runnable() {
@Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
Espresso: how to scroll to the bottom of ScrollView
If at the bottom of the ScrollView you need to find a view and match something against it, then simply perform the scrollTo()
action on it, before any other actions that require it to be displayed.
onView(withId(R.id.onBottomOfScrollView))
.perform(scrollTo(), click());
Note: scrollTo will have no effect if the view is already displayed so you can safely use it in cases when the view is displayed
Why does my android activity always start scrolled to the bottom?
When Android starts an activity, some control needs to take focus. When there's no designated control to take focus, the system chooses the first eligible control that wants focus.
If you set the following property in your LinearLayout - android:focusableInTouchMode="true"
your LinearLayout
will be focused on start and your activity won't scroll to EditText
in the bottom.
How to make activity start at the bottom of the ScrollView?
ScrollView scrollview = findViewById(R.id.scrollView);
scrollview.post(new Runnable() {
@Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
How to do actions when scroll view reached bottom end?
I have done this things with webView here is my code, hope it will help you.
webView.setOnScrollChangedCallback(new ObservableWebView.OnScrollChangedCallback() {
@Override
public void onScroll(int l, int t) {
int tek = (int) Math.floor(webView.getContentHeight() * webView.getScale());
if (tek - webView.getScrollY() <= webView.getHeight() + 5) {
// enable your button
}
}
});
this is the class
public class ObservableWebView extends WebView
{
private OnScrollChangedCallback mOnScrollChangedCallback;
public ObservableWebView(final Context context)
{
super(context);
}
public ObservableWebView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
}
public ObservableWebView(final Context context, final AttributeSet attrs, final int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(final int l, final int t, final int oldl, final int oldt)
{
super.onScrollChanged(l, t, oldl, oldt);
if(mOnScrollChangedCallback != null) mOnScrollChangedCallback.onScroll(l, t);
}
public OnScrollChangedCallback getOnScrollChangedCallback()
{
return mOnScrollChangedCallback;
}
public void setOnScrollChangedCallback(final OnScrollChangedCallback onScrollChangedCallback)
{
mOnScrollChangedCallback = onScrollChangedCallback;
}
/**
* Impliment in the activity/fragment/view that you want to listen to the webview
*/
public static interface OnScrollChangedCallback
{
public void onScroll(int l, int t);
}
}
happy coding.
Related Topics
How to Run a Service Every Day at Noon, and on Every Boot
How to Get Profile Like Gender from Google Signin in Android
Run Task Before Compilation Using Android Gradle Plugin
What Is Setcontentview(R.Layout.Main)
How to Pause Frame Animation Using Animationdrawable
How to Show Toast in Asynctask in Doinbackground
Certpathvalidatorexception:Trust Anchor for Certificate Path Not Found - Retrofit Android
How to Import Set of Icons into Android Studio Project
Using Actionbarsherlock with the New Supportmapfragment
How to Add an Image File into JSON Object
Error: Configuration with Name 'Default' Not Found in Android Studio
How to Read CPU Frequency on Android Device
Changing Screen Brightness Programmatically in Android
Firebase:Differencebetween Setpersistenceenabled and Keepsynced
Android Devices with Different Height Takes Same Layout Folder
Keyboard Not Shown When I Click on Edittextview in Android