HorizontalScrollView, auto-scroll to end with animation - android

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();

Related

How to scroll with animation

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

How to Autoscroll to bottom on listview?

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.

How to scroll ListView to the bottom?

I though this would be a simple task, but apparently there is no way to scroll listview to the bottom. All solutions that I found are using variations of setSelection(lastItem) method which only sets selection to last item, but does not scrolls to the bottom of it.
In my case I have a empty listview (with a long empty view header set) and I want to scroll to bottom of it.
So, is there a way to do it?
Edit:
So for those who are interested the working solution is:
getListView().setSelectionFromTop(0, -mHeader.getHeight());
and
getListView().scrollTo(mOffset)
This also works, with right offset (calculated based on current scroll position), but might give you some unexpected results.
If you want the list view to be scrolled always at the bottom even when you are updating the list view dynamically then you can add these attributes in list view itself.
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
use the following
lv.setSelection(adapter.getCount() - 1);
If you would like to have a scroll animation programmatically you could easily scroll to the bottom of the list using:
listView.smoothScrollToPosition(adapter.getCount());
scrolling to the top most of the list can be achieved using:
listView.smoothScrollToPosition(0);
Try this one.. it will solve your problem, i tried it and it works great.
listView.post(new Runnable(){
public void run() {
listView.setSelection(listView.getCount() - 1);
}});
private void scrollMyListViewToBottom() {
myListView.post(new Runnable() {
#Override
public void run() {
// Select the last row so it will scroll into view...
myListView.setSelection(myListAdapter.getCount() - 1);
}
});
}
Its working for me
Use following and try.
listview.setSelection(adapter.getCount()-1);
You might want to try myListView.smoothScrollToPosition(myListView.getCount() - 1). This way, you're not forced into selecting the last row. Plus, you get some smooth, beautiful scrolling! (:
I Had the same problem, This works best for me
listView.setSelection(listView.getAdapter().getCount()-1);
if there is no adapter set to your ListView then it has no children at all, empty view is not a child of your ListView
Try using list.scrollTo(0, list.getHeight());

android scrollview animation

I am trying to animate a Scrollview.
Particularly the SmoothScrollTo(x,y) function. Any ideas on how I go about this.
Thanks
ScrollView scroller = (ScrollView) findViewById(R.id.scroller);
if(true){
scroller.smoothScrollTo(0,30);
animation anim = AnimationUtils.loadAnimation(this, R.anim.down);
anim.setFillAfter(true);
scroller.startAnimation(anim);
} else{
.....
}
If you want to achieve smooth scrolling there is no need to animate the scroll.
Use reflection to set up your own custom Scroller & Interpolator.
something like this:
Field mScroller;
mScroller = ScrollView.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
CustomScroller scroller = new CustomScroller(getContext(), new AccelerateInterpolator());
mScroller.set(this, scroller);
Surround Try/Catch & there u go.
user smoothScrollTo method.
Im not sure whether you add animation to the scroller. I maybe wrong. One method would be to use the Timer and TimerTask to schedule a task to increment/decrement the scrollTo values.
You can vary the interval in which the task executes to speedup and slow down the scrolling.

Android: how to force ScrollView layout, and then scroll to a point?

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

Categories

Resources