Android
애플리케이션을 개발 중이며 OnTouch
을 전체 화면에 캡쳐하려고합니다.. 모두 내 activities
은 두 개의 buttons
헤더와 그 다음 변경 될 본문이 있습니다. Activity
에서Android : 루트보기 (RelativeLayout)의 onTouchListener가 작동하지 않습니다.
나는 몸이 ListView
입니다 지금 테스트 해요, 그래서 Activity
가 있습니다
- 두 Buttons
을 화면 상단에.
- ListView
이러한 두 개의 버튼 아래.
전체 화면에서 onTouchEvents
을 캡처하고 싶습니다.. OnTouchListener
을 내 루트 RelativeLayout
으로 설정하고 clickable = false 및 focusable = false를 다른 모든보기에 설정했지만 작동하지 않습니다. onTouch 이벤트는 첫 번째 버튼을 클릭했을 때만 트리거됩니다. 이것은 @ 레이아웃/헤더의 내용입니다
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity" >
<include
layout="@layout/header"
android:clickable="false"
android:focusable="false" />
<ListView
android:id="@+id/lvLocations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header_layout"
android:clickable="false"
android:focusable="false" />
</RelativeLayout>
:
이
내 레이아웃입니다<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:weightSum="5" >
<Button
android:id="@+id/homeButton"
android:layout_width="0dip"
android:layout_height="50dp"
android:layout_marginRight="5dp"
android:layout_weight="4"
android:clickable="false"
android:focusable="false"
android:onClick="Home"
android:text="@string/home" />
<ImageButton
android:id="@+id/speechButton"
android:layout_width="0dip"
android:layout_height="50dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:onClick="ClickMediaButton"
android:src="@drawable/micro" />
</LinearLayout>
는 그리고 이것은 내가 사용하는 코드입니다 :
findViewById(R.id.root).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("MACT", "TOUCH!");
}
});
내가 말했듯이 홈 로그 버튼을 클릭 한 경우에만 내 로그에 TOUCH 이 표시됩니다.. 왜 그런가요? 내가 도대체 뭘 잘못하고있는 겁니까?
감사합니다.
흥미 롭습니다. 필자가 생각하는 것은 터치를 캡처하는 여러보기 (예 : 목록보기, 머리글, 단추)가 있기 때문에 원하는 방식으로도이를 알릴 수 없기 때문입니다. 나는 당신이 커스텀 뷰를 만들었고, 그것들 중 하나가 움켜 잡기 전에 터치를 붙잡은 다음, 디렉터 타입 패턴을 사용하여 어떤 일이 발생했는지를 결정하는 것은보다 복잡한 레이아웃에서 일어날 수 있다고 확신한다. 이전에 viewpagers에지도 또는 그리드를 배치하는 것과 비슷한 문제가있었습니다. 그냥 생각. – Rarw
정말 재미있는 의견, 나는 결코 많은 것을 사용자 지정보기로 가져 가지 않아서, 이것에 대해 생각하지 않았습니다. 좋은 접근 방식처럼 보인다 :) –