我在导航栏中使用以下xml文件
XML:
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<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">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</FrameLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:id="@+id/drawer_frame"
android:background="@drawable/list_selector"
>
<LinearLayout
android:id="@+id/header"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="@drawable/list_selector"
android:clickable="true"
android:onClick="Login"
>
<ImageView
android:id="@+id/DisplayImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:src="@drawable/displayimage"
android:contentDescription="@string/contentdescription"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="vertical" >
<TextView
android:id="@+id/Displayname"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:layout_marginRight="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/counter_text_color"
android:textSize="14sp"
android:text="@string/Signin"
android:gravity = "center"
/>
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/card_background"
android:dividerHeight="1dp"
android:background="@drawable/list_selector"
android:layout_marginTop="5dp"
android:layout_below="@+id/view1"
/>
<include android:id="@+id/progressinformation" layout="@layout/emptyview"/>
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/header"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:background="@color/card_background"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
我将包含设置为 left_drawer 的空视图(left_drawer.setEmptyView(R.id.progressinformation))。
我的问题是,假设当我点击导航抽屉时,listview为空,导航抽屉后面的元素正在选择。列表视图为空时如何避免这种选择。
答案 0 :(得分:1)
不确定是否正确理解,但您必须将导航抽屉布局参数设置为true
<RelativeLayout
android:layout_width="240dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:id="@+id/drawer_frame"
android:background="@drawable/list_selector"
android:clickable="true"
>