android - how to align one image to another after sliding with a finger? -


i have activity.xml

the user can move these boxes (buttons) finger right , left.

however white small arrow doesn't reach middle of box

(sometimes right, left)

enter image description here

i have tried add/remove margine left.

but didn't help.

enter image description here

where should around?

 <com.w.navigate.searchbuttonsbarhorizontalscrollview         android:id="@+id/searchbuttonbar"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:background="@drawable/engines_bg"         android:fadingedge="horizontal"         android:gravity="center"         android:padding="0dp"         android:scrollbars="none" >          <linearlayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:gravity="center_horizontal"             android:orientation="horizontal"             android:paddingtop="25dp" >              <imagebutton                 android:id="@+id/leftmargin"                 android:layout_width="110dp"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@drawable/search_engine_button"                 android:visibility="invisible" />              <imagebutton                 android:id="@+id/searchbutton1"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@drawable/search_engine_button"                 android:onclick="engineclicked" />              <imagebutton                 android:id="@+id/searchbutton2"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@drawable/search_engine_button"                 android:onclick="engineclicked" />              <imagebutton                 android:id="@+id/searchbutton3"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@drawable/search_engine_button"                 android:onclick="engineclicked" />              <imagebutton                 android:id="@+id/searchbutton4"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@drawable/search_engine_button"                 android:onclick="engineclicked" />         </linearlayout>     </com.w.navigate.searchbuttonsbarhorizontalscrollview> 

maybe fix should in code:

public boolean ontouchevent(motionevent event) {     super.ontouchevent(event);     log.d("w","ontouchevent");           if (event.getaction()==motionevent.action_up) {         log.d("waze","action up");         integer min_dist=null;         searchengine min_se=null;         @suppresswarnings("unchecked")         map<object, searchengine> engines=(map<object, searchengine>)gettag(r.id.searchengines);         iterator<searchengine> i=engines.values().iterator();         while (i.hasnext()) {             searchengine tmp_se=(searchengine)i.next();             int tmp_dist=math.abs(tmp_se.getbutton().getbuttonxposition()-getscrollx()-getwidth()/2);             if (min_dist==null || tmp_dist<min_dist) {                 min_dist=tmp_dist;                 min_se=tmp_se;             }         }         ((searchactivity)gettag(r.id.searchactivity)).setactiveengine(min_se);     }     return true;  } 

i think problem comes :

android:layout_alignparentbottom="true" 

with this, arrow aligned parent (the button). searched on android developpers , found xml attribute usefull :

android:layout_centerhorizontal="true" 

in android developper, here decription :

if true, centers child horizontally within parent.

hope it'll work; i'm new on stackoverflow, maybe answer isn't well-formatted.


Comments