2

I have an activity.xml

The user can move these boxes (buttons) with his finger to the right and to the left.

However the white small arrow doesn't reach to the middle of the box

(sometimes too right, sometimes too left)

enter image description here

I have tried to add/remove margine to its left.

But it didn't help.

enter image description here

Where should I look 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 the fix should be in the 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;

}
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

0

I think your problem comes from :

android:layout_alignParentBottom="true"

With this, your arrow is aligned with your Parent (the button). I searched on android developpers and I found a xml attribute which could be very usefull for you :

android:layout_centerHorizontal="true"

In Android Developper, here is the decription :

If true, centers this child horizontally within its parent.

Hope it'll work; I'm new on StackOverflow, maybe my answer isn't well-formatted.

Laurent Meyer
  • 2,766
  • 3
  • 33
  • 57
  • nope. It made the bottom bar to be at the top of my screen. btw, I want the triangle be center after the user swap the buttons with his finger, not on the static initial position – Elad Benda Jul 13 '13 at 11:51
0

If I'm not mistaken, take a look at the pointing arrow location - It's simply not located in the horizontal middle of the screen. you are actually doing everything right in the scroll view.

Take a real screenshot from the application to test it out.

Sean
  • 5,176
  • 2
  • 34
  • 50
  • you're right, that's why I have posted this one: http://stackoverflow.com/questions/17702609/why-is-my-9png-photo-si-starched-to-the-right?noredirect=1#comment25866184_17702609 and yet I'm not sure why in the editor it's in the middle whereas in the application itslef it's not – Elad Benda Jul 20 '13 at 18:14