我有一个activity.xml
用户可以用手指左右移动这些框(按钮)。
但是白色的小箭头没有到达盒子的中间
(有时太右,有时太左)
我试图在其左侧添加/删除边距。
但这没有帮助。
我应该在哪里环顾四周?
<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>
也许修复应该在代码中:
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;
}