• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps horozontal scroll view not accurate

elad2109

Lurker
Apr 15, 2011
4
0
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:
     <com.w.n.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" />
       </com.w.n.SearchButtonsBarHorizontalScrollView>


Maybe the fix should be in the code of my SearchButtonsBarHorizontalScrollView

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;
    	
    }
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones