java - how to make scrollTo stop where I intend? -


i have horizontal scroll bar icons (buttons) on it.

i try move selected icon middle of bar.

i have read post positioning views in android.

i have got code, seems logically ok me:

    public void selectbutton() {  ...             horizontalscrollview sv=(horizontalscrollview)button.getparent().getparent();             int offsetx=getbuttonxposition()-sv.getwidth()/2;             sv.smoothscrollto(offsetx, 0);  ..     }       public int getbuttonxposition() {         return (button.getleft()+button.getright())/2;     } 

i move left top corner a pixels right\left (negative\positive number of pixels),

where a = x position of middle of selected button - middle of bar.

meaning want move middle of button a pixels right\left (negative\positive)

however buttons stop left\right (if it's rightmost\leftmost button)

see images attached:

enter image description here

enter image description here

try this....

<horizontalscrollview     android:id="@+id/scrollview1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true">      <linearlayout         android:id="@+id/linearlayout1"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"           android:layout_margin="10dp">      </linearlayout> </horizontalscrollview> 


for (int x = 0; x < imageslist.size(); x++) {     imagehor = new imageview(fullimagescreennew.this);     linearlayout.settag(x);     imagehor.setimagebitmap(decodesampledbitmapfromresource(imageslist.get(x)));      linearlayout.layoutparams llp = new linearlayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content);     llp.setmargins(10, 10, 10, 10); // 4 margin values top/left/right/bottom     linearlayout.addview(imagehor, llp); }  linearlayout.setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             (int = 0; < imageslist.size(); i++) {                    indexnumber.add(i);                 int index = indexnumber.indexof(i);                 log.e("indexvalue=====", "" + index);                 awesomepager.setcurrentitem(index, true);             }         } }); 

Comments