1. Are you ready for the Galaxy S20? Here is everything we know so far!

horozontal scroll view not accurate

Discussion in 'Android Development' started by elad2109, Jul 13, 2013.

  1. elad2109

    elad2109 Lurker
    Thread Starter

    I have an xml layout with my custom view (bottom horizontal scroll view).


    In the middle of the view there is a small tirangle showing which is the currently selected box.

    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


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

    But it didn't help.

    Where should I look around?



    part of the xml:

    Code (Text):
    1.      <com.w.n.SearchButtonsBarHorizontalScrollView
    2.             android:id="@+id/searchButtonBar"
    3.             android:layout_width="wrap_content"
    4.             android:layout_height="wrap_content"
    5.             android:layout_alignParentBottom="true"
    6.             android:background="@drawable/engines_bg"
    7.             android:fadingEdge="horizontal"
    8.             android:gravity="center"
    9.             android:padding="0dp"
    10.             android:scrollbars="none" >
    11.    
    12.             <LinearLayout
    13.                 android:layout_width="wrap_content"
    14.                 android:layout_height="wrap_content"
    15.                 android:gravity="center_horizontal"
    16.                 android:orientation="horizontal"
    17.                 android:paddingTop="25dp" >
    18.    
    19.                 <ImageButton
    20.                     android:id="@+id/leftMargin"
    21.                     android:layout_width="110dp"
    22.                     android:layout_height="wrap_content"
    23.                     android:layout_weight="1"
    24.                     android:background="@drawable/search_engine_button"
    25.                     android:visibility="invisible" />
    26.    
    27.                 <ImageButton
    28.                     android:id="@+id/searchButton1"
    29.                     android:layout_width="wrap_content"
    30.                     android:layout_height="wrap_content"
    31.                     android:layout_weight="1"
    32.                     android:background="@drawable/search_engine_button"
    33.                     android:onClick="engineClicked" />
    34.    
    35.                 <ImageButton
    36.                     android:id="@+id/searchButton2"
    37.                     android:layout_width="wrap_content"
    38.                     android:layout_height="wrap_content"
    39.                     android:layout_weight="1"
    40.                     android:background="@drawable/search_engine_button"
    41.                     android:onClick="engineClicked" />
    42.    
    43.                 <ImageButton
    44.                     android:id="@+id/searchButton3"
    45.                     android:layout_width="wrap_content"
    46.                     android:layout_height="wrap_content"
    47.                     android:layout_weight="1"
    48.                     android:background="@drawable/search_engine_button"
    49.                     android:onClick="engineClicked" />
    50.        </com.w.n.SearchButtonsBarHorizontalScrollView>

    Maybe the fix should be in the code of my SearchButtonsBarHorizontalScrollView

    Code (Text):
    1.     public boolean onTouchEvent(MotionEvent event) {
    2.         super.onTouchEvent(event);
    3.         Log.d("w","ontouchevent");     
    4.         if (event.getAction()==MotionEvent.ACTION_UP) {
    5.             Log.d("WAZE","action up");
    6.             Integer min_dist=null;
    7.             SearchEngine min_se=null;
    8.             @SuppressWarnings("unchecked")
    9.             Map<Object, SearchEngine> engines=(Map<Object, SearchEngine>)getTag(R.id.searchEngines);
    10.             Iterator<SearchEngine> i=engines.values().iterator();
    11.             while (i.hasNext()) {
    12.                 SearchEngine tmp_se=(SearchEngine)i.next();
    13.                 int tmp_dist=Math.abs(tmp_se.getButton().getButtonXPosition()-getScrollX()-getWidth()/2);
    14.                 if (min_dist==null || tmp_dist<min_dist) {
    15.                     min_dist=tmp_dist;
    16.                     min_se=tmp_se;
    17.                 }
    18.             }
    19.             ((SearchActivity)getTag(R.id.searchActivity)).setActiveEngine(min_se);
    20.         }
    21.         return true;
    22.        
    23.     }
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...