2

当我放入ScrollViewa 的内容时DrawerLayout,我不再能够通过从侧面滑动来打开抽屉。

活动布局:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<!-- The menu_main content view -->
<FrameLayout
        android:id="@android:id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
<!-- The navigation drawer -->
<ListView
        android:name="com.gumtree.androidapp.DrawerFragment"
        android:id="@+id/drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>

在 Activity 中onCreate,我添加了一个具有以下布局的片段:

<ScrollView
    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">

<LinearLayout
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ImageView
            android:layout_height="160dp"
            android:layout_width="match_parent"/>

    <TextView
            android:id="@+id/headline"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/headline_text_size"
            android:padding="@dimen/detail_text_padding"
            android:textIsSelectable="false"/>

    <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/description_text_size"
            android:padding="@dimen/detail_text_padding"
            android:textIsSelectable="false"/>


</LinearLayout>
</ScrollView>

如果没有ScrollView一切正常,我可以通过从侧面滑动来打开抽屉。但是,当我添加 时ScrollView,它停止工作。

4

1 回答 1

1

这里的问题是愚蠢的命名 IDFrameLayout用作DrawerLayout. 我使用了系统 ID ( android.R.id.content),这导致内容片段被放在所有其他视图的顶部——甚至是抽屉。

It also caused fragment's layout to overlap the drawer and - related to this question - blocked the drawer from receiving touch events. The touch events were taken by fragment's ScrollView.

Conclusion: DO NOT USE SYSTEM IDs (android.R.*) WHERE IT IS NOT NEEDED.

I just wanted it to look nice and clean.. Silly me :)

于 2013-08-27T12:55:02.237 回答