I want to scroll to the end of the view. Currently i am trying to scroll the scrollview to the end of the latest added view. I tried with setscrolly, smoothscrollto. both works but the problem is both wont scroll to the end, it just scrolls to the last-1 view. Please suggest me how to overcome this.
I got the reason why it was not scrolling to the last view and was stopping at the last-1 view. I was not smoothScrollTo(x,y) in a post thread of the view. Since my scrollview is not refreshed when the last view is added it was not scrolling to the last view.
view.post(new Runnable() {
public void run() {
scrollview.smoothScrollTo(x,y);
});
Try to use transcript mode param of list view. It provides scrolling to new items automatically:
getListView().setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
Related
I have a bunch of view in ScrollView.
Some of them are TextInputEditText.
When an error occurs I use setError for particular TextInputEditText.
And I have such effect.
But my layout is long, and I need to scroll to view with an error.
Code:
protected void showInputError(TextInputEditText edtText, #StringRes int resId) {
edtText.setError(getString(resId));
scrollView.post(() -> {
scrollView.scrollTo(0, edtText.getTop());
});
}
All works fine first time. But the app does the same scrolling after any other scrolling.
I mean,
set an error to view
scroll programmatically to this view
scroll manually to another place. Application scrolls again to view from step 2.
The main problem: Application scrolls back to view when user scrolls manually (after applying of scrollTo)
Please, give a hint how to overcome this
When a button is clicked, I would like the app to smoothly scroll to the bottom of a listview. Currently this is my implementation (kotlin)
listview.post { listview.smoothScrollToPosition(adapter.count - 1) }
However, this does not always work properly: Some list items contain some expandable parts (i.e. view whose visibility can be VISIBLE or GONE), which initially are hidden.
When these parts are expanded however, the function sometimes does not scroll to the end, but to a position before the end.
How can I reliably scroll to the end of the listview?
Try following. it will solve your problem, i tried it and it works great.
listView.post(new Runnable(){
public void run() {
listView.setSelection(listView.getCount() - 1);
}});
add android:transcriptMode="alwaysScroll"
to the ListView block in xml
Hope you can help me, this has been bugging me for quite some time now-
I have an activity that at some point inflates a view which has its own layout and logic behind. This view contains a ScrollView which I want to be scrolled down x dp when its shown to the user (I don't want user to actually see the scrolling, I want ScrollView to be at the right position as the view displays).
Here's what I tried so far:
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.scrollTo(0, someInnerView.getBottom());
}
});
I've tried using this code in different parts of my view logic such as onFinishInflate() but that doesn't work as the data isn't binded to the view at that point. So I added OnGlobalLayoutListener and called the Runnable inside onGlobalLayout() which does work but with a short delay which can clearly be detected.
How do I solve this problem? All I want to do is to have some part of my ScrollView hidden when it's presented to the user.
All help appreciated!
EDIT : to make my intentions clearer- I want to create something similar to this, only that I'm using ScrollView
I've having a chat app, if the ListView items are not enough to scroll then the row should be at the top of the list. If the items are enough to trigger scroll then the list should scroll always scroll down to show the latest conversation like in the iMessage setup.
I tried adding in the XML:
android:stackFromBottom="true"
but this would cause the ListView to scroll down ALWAYS. I only want to scroll down if the items are enough to cause scrolling, if not then it should scroll up.
I would use this if I could detect the enabling of scroll:
myListView.post(new Runnable() {
#Override
public void run() {
// Select the last row so it will scroll into view...
myListView.setSelection(myListAdapter.getCount() - 1);
}
});
So how would I detect if the ListView items are enough to trigger scroll?
You could try this to detect the scrollable
if (yourListView.getLastVisiblePosition() == yourListView.getAdapter().getCount() -1)
{
//It is scrolled all the way down here
}
to check the last visible item is still smaller the item number :)
I fixed this by placing this code listView.setSelection(rowAdapter.getCount()); after listView.setAdapter(rowAdapter);. When chat messages are only few, it is scrolled up and when the messages are enough to trigger scroll then it is scrolled to the bottom. Just like I want it.
Why is it when I insert a list view into a scrollview, the list view stops scrolling.
The Scroll View scrolls normally, but the list view seems as if it is frozem
Well it seems that you must not place a list view inside a scroll view, because the system will not know which control to scroll!
There is no need to add listview in scrollview since scrolling is a default property for
ListView. That is all.
Please go through the Android documentation before design any of the UI.