【发布时间】:2014-11-09 02:26:04
【问题描述】:
当我在我创建的 Android 应用程序中打开导航抽屉时,我仍然可以单击主布局(内容布局)中的列表项。我的意思是,我实际上可以通过我的导航抽屉点击ListView 项目。我的导航抽屉中还没有任何可点击的项目,但我已将其放入具有白色背景的正确FrameLayout 中。抽屉的内容,我在一个片段中设计。这是我的代码:
activity_home.xml (MainActivity)
<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"
android:background="@android:color/white"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar_home"
layout="@layout/my_awesome_toolbar" />
<FrameLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/fab_addContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="@dimen/view_margin_large"
android:layout_marginEnd="@dimen/view_margin_large"
android:layout_marginRight="@dimen/view_margin_large"
android:background="@drawable/fab_button"
android:contentDescription="@string/fab_contDesc"
android:padding="@dimen/view_margin_large"
android:src="@drawable/ic_add_white_24dp" />
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/drawer_frame"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:clickable="true" />
</android.support.v4.widget.DrawerLayout>
fragment_drawer.xml(DrawerFragment 进入@+id/drawer_frame)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="144dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/material_design_wallpaper" />
<ImageView
android:id="@+id/iv_userThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="16dp"
android:background="@drawable/display_pic_thumbnail"
android:contentDescription="@string/contact_thumbnail" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/view_margin_xx_large"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/shadow" />
<TextView
android:id="@+id/tv_userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/tv_userEmail"
android:layout_alignLeft="@+id/tv_userEmail"
android:layout_alignStart="@+id/tv_userEmail"
android:layout_marginBottom="@dimen/view_margin_small"
android:text="Siddhant Chavlekar"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_userEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="@dimen/view_margin_large"
android:layout_marginLeft="@dimen/view_margin_large"
android:layout_marginStart="@dimen/view_margin_large"
android:text="siddhant.chavlekar87@gmail.com"
android:textColor="@android:color/white" />
</RelativeLayout>
</LinearLayout>
为什么会这样?我正在使用 AppCompat v7:r21 库为我的 Lollipop(材料设计)应用程序提供向后兼容性。
【问题讨论】:
-
我在 android 21 发布之前就有过这种体验,我通过在 DrawerLayout
android:clickable="true"987654327@ 内的布局中添加这一行来解决它 -
@k0sh 那么我应该将它添加到我的
DrawerLayout内的所有布局中还是只添加到抽屉中? -
不,你将它添加到抽屉布局内的布局中,除了要容纳抽屉子级的布局
-
@k0sh 嘿,我在
drawer_frame中添加了这条线,一切似乎都很好。所以我想这两种方式都可以吧?把它放到抽屉里有什么危险吗??
标签: android android-listview navigation-drawer android-appcompat click-through