LoginSignup
4
5

More than 5 years have passed since last update.

DrawerLayoutをタッチすると、下のアイテムのタッチイベントになる問題の対策(Mapだけ?)

Last updated at Posted at 2015-02-02

DrawerLayout on MapFragment

以下のようなレイアウトでアプリ実行、DrawerLayoutを引き出した後にTextViewをタップすると、MapFragmentのタッチイベントが発火してしまっていた。

activity_main
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The main content view -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
            android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_alignRight="@+id/fragment"
            android:layout_alignEnd="@+id/fragment" />
    </LinearLayout>

    <!-- The navigation drawer -->
    <LinearLayout
        android:id="@+id/right_drawer"
        android:orientation="vertical"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#DDDDDD"
        android:paddingRight="16dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:paddingLeft="56dp">
        <TextView
            android:id="@+id/drawer_address_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="null" />

        <ListView android:id="@+id/drawer_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:paddingLeft="8dp" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

ダメだった対策

getParent().requestDisallowInterceptTouchEvent(true); をする。
参考:http://blog.livedoor.jp/txmy/archives/52182923.html
→ダメでした

動いた対策(?)

DrawerLayoutの一番上のViewのClickableをtrueにする。
今回の場合なら(idがright_drawerのLinearLayout).setClickable(true);ですね
自分はコード上でやったけど、layoutのxmlでandroid:clickable="true"にしても一緒だと思う
参考:http://stackoverflow.com/questions/21380317/navigation-drawer-disable-backview-when-drawer-open
→オッケー

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5