I have a activity that shows a howizontalscrollview with a horizontally long imageview.
I need that when the activity starts, the horizontalscrollview must be scrolled to the center of itselft, and not to the start.
I'm searching on google and here and i can't find the way..
this is my horizontal scroll view:
HorizontalScrollView wvScroll = new HorizontalScrollView(this);
wvScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
iv.setImageBitmap(Util.getRemoteImage("http://mywebsite.com/90.gif"));
iv.setScaleType(ScaleType.CENTER_CROP);
wvScroll.addView(iv);
mainLayout.addView(wvScroll);
Thanks
HorizontalScrollView is used to scroll the child elements or views in a horizontal direction. HorizontalScrollView only supports horizontal scrolling. For vertical scroll, android uses ScrollView.
Try:
wvScroll.scrollTo(offsetX, 0);
There may be a timing issue, where the offset will be set before the scrollView is created. In that case, use postDelayed()
with a runnable
that calls scrollTo
ADDED:
To use postDelayed():
private Handler mHandler = new Handler();
in onCreate do:
mHandler.postDelayed(new Runnable(){
public void run() {
wvScroll.scrollTo(offsetX, 0);
}
}, 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With