我一直在試圖找到一個這個小時的解決方案,感覺就像我搜索了每一個關於stackoverflow的問題,並試圖在佈局中的一切。 在我嘗試下面顯示的佈局之前,edittext和兩個圖像按鈕位於scrollview內。在這個舊的佈局中,ontouch在我的片段中完美工作,但是一旦我用edittext和兩個圖像按鈕拉出相對佈局,ontouch就不會被觸發。有人可以幫我解決這個問題嗎?任何幫助表示讚賞。由於在RelativeLayout中使用ScrollView的片段> ontouch不起作用
View fragmentView = inflater.inflate(R.layout.request, container, false);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#BDCCE0" >
<EditText
android:id="@+id/etsearch"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="10dp"
android:hint="search..."
android:singleLine="true"
android:imeOptions="actionDone" />
<ImageButton
android:id="@+id/bsearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/etsearch"
android:layout_marginTop="9dp"
android:src="@drawable/search" />
<ImageButton
android:id="@+id/bupdaterequests"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toRightOf="@id/bsearch"
android:layout_marginTop="9dp"
android:src="@drawable/refresh" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#BDCCE0"
android:layout_below="@id/etsearch" >
<TableLayout
android:id="@+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
</RelativeLayout>
所以我應該怎麼解決這個問題? – Max
你想讓RelativeLayout的OnTouchListener做什麼?它會衝突其他視圖的基本功能嗎? – Sam
基本上我只想當有人觸摸編輯文本之外的鍵盤消失。我有通常與觸摸一起工作的代碼,但由於ontouch不會觸發,我不知道如何解決此問題。 – Max