I am trying to create an app for which i need to scroll down programmatically upon receiving some message..
I have tried using ScrollView using following code
ScrollView mScrollView;
mScrollView = (ScrollView)findViewById(R.id.abc);
mScrollView.post(new Runnable() {
public void run() {
mScrollView.scrollTo(0, mScrollView.getBottom());
}
});
It works and it takes me to bottom , but there's no animation like actual scrolling.
How can i get "scrolling animation" along with that?
is there any other way to scroll programmatically with animation? please help me out.
try using ScrollView.smoothScrollTo method
Related
I have application with ListView. This ListView has a Progressbar.When I am clicking on this Progressbar, then it is showing a hided Layout(This layout contain textview with lyrics). So as I am clicking on the last Progressbar then it is showing the hided Layout, but I need to scroll manually. I want that scrolling must be automatically.
Please help me.
Try something like this:
private void scroll2bottom() {
yourListView.post(new Runnable() {
#Override
public void run() {
yourListView.setSelection(yourListAdapter.getCount() - 1);
}
});
}
You might find the smoothScrollByOffset() or smoothScrollBy() methods of ListView most useful. In particular smoothScrollBy() takes both a distance to scroll and a duration over which the scroll animation should take place. With this method you can control precisely how far to scroll the list.
in your layout of your listview just use the transcriptMode
a listview has builtin auto scroll
android:transcriptMode="normal" witll scroll when its at the bottom but not when you have scrolled away
and the setting alwaysScroll will always scroll to the bottom
and then you can set the android:stackFromBottom="true" to make it grow from the bottom
Try in this way:
lv.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
lv.setStackFromBottom(true);
To scroll a listView programmatically you can use its smoothScrollByOffset(int offset) or smoothScrollToPosition(int position) methods, you can find here the documentation about the ListView widget and how to use those methods.
In my app, I have a ScrollView with a LinearLayout whose visibility is set on GONE.
I need to make it visible and then have my ScrollView scroll to the bottom of the LinearLayout.
For this I'm using this code:
mLinearLayout.setVisibility(View.VISIBLE);
mScrollView.smoothScrollTo(0, mLinearLayout.getBottom());
This however, does not work. When the ScrollView is asked to scroll the LinearLayout still returns 0 on getBottom().
So when this is called for the first time, the LinearLayout is visible, but the scrollview has not scrolled.
When it is called for a second time, it does scroll down to the right position.
How can I fix this?
You need to put your smmothScrollTo method inside a new thread like this:
mScrollView.post(new Runnable() {
public void run() {
mScrollView.smoothScrollTo(0,mLinearLayout.getBottom());
}
});
this is not a repeat of another question.. it's more an expansion. I hope :)
I've a list view with a few hundred items in it.. They are date stamped entries in another view.
When I show the screen I want it to scroll to the bottom, so the most recent items are displayed, but in a logical "end of the thing" sort of way.
m_list.setSelection(m_list.getCount()-1);
Kewl as... but :( Now my list won't scroll. It seem stuck on the bottom. I can see the "truck" and it's tiny and at the bottom.
Ok.. so my questy is thus.. How do I start off by scrolling to the bottom, but still allow the user (me) to scroll up when they (me again) want to scroll up.
set the following on your listview in the XML.
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
You can use following code to reach at bottom of list view.
listView.postDelayed(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
}
}, 500);
This will set delay of 500 ms. Or you can use
listView.post(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
}
});
This will scroll your list view pragmatically.
I have a horizontalScrollView and I need to make an auto-scroll to end with animation when I load the view. I have implemented this method to do it:
final HorizontalScrollView strip = (HorizontalScrollView) contentView.
findViewById(R.id.horizontalScrollView1);
strip.postDelayed(new Runnable() {
public void run() {
strip.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 1000L);
It works fine, but, the main problem is the animation of the scrolling is too fast and I need to implement a slower scrolling. Have you any idea?
This is a demo project I created for one of my projects. Its a scroller the scroll automatically and continously. It was made to show a credits screen by continously scrolling through a list of images.
This might help you or give you some idea.
https://github.com/blessenm/SlideshowDemo
Try this:
ObjectAnimator animator=ObjectAnimator.ofInt(buttonHolderScrollView, "scrollX",targetXScroll );
animator.setStartDelay(100);
animator.setDuration(100);
animator.start();
I have a ScrollView which I'm adding a number of custom Views to. After adding the custom Views, I would like to be able to Scroll to a particular one. But, immediately after adding the custom views, the ScrollView hasn't been resized, so I can not scroll. Any idea how I can force this resize?
for(int i = 0, i < numberOfViews, i++)
{
scrollView.addView(new MyView(...));
}
//tried this, doesn't seem to be helpful
scrollView.requestLayout();
//at this point scrollView dimensions are 0,0,0,0
scrollView.scrollTo(5, 200);
I'm not completely sure what you're trying to do, but I wanted to scroll all the way down, and couldn't just do that: I had to do it like this:
((ScrollView) findViewById(R.id.yourId)).post(new Runnable() {
public void run() {
((ScrollView) findViewById(R.id.yourId)).fullScroll(View.FOCUS_DOWN);
}
});
It will update later, so your view is made :)
An elegant solution is to plan the scroll and do it on the next onLayout(). Example code here:
https://stackoverflow.com/a/10209457/1310343