【问题标题】:Multipe List views in Drawer layout in AndroidAndroid中抽屉布局中的多个列表视图
【发布时间】:2014-06-05 12:07:36
【问题描述】:

我正在使用自定义列表视图在我的应用程序中显示数据,然后我尝试添加导航抽屉

点击抽屉布局不起作用。它最终打开了自定义列表视图,因为它位于抽屉列表视图的后面。抽屉列表视图永远不会获得焦点,即使抽屉打开了

以下是我的主要活动 xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"/>
</android.support.v4.widget.DrawerLayout>
<ListView
android:id="@+id/listScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="7dp">
</ListView>
</RelativeLayout>

【问题讨论】:

  • 请检查 Spirit 的回答是否已接受,有什么问题?

标签: android navigation drawer


【解决方案1】:

这样使用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<include layout="@layout/actionbar" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- The main content view -->

    <include layout="@layout/activity_main" />

    <!-- The navigation drawer -->

    <include layout="@layout/drawer_layout_right" />

    <include layout="@layout/drawer_layout_left" />
</android.support.v4.widget.DrawerLayout>

drawer_layout_right.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="horizontal" >

<ListView
    android:id="@+id/lv1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

</LinearLayout>

drawer_layout_left.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical" >

<ListView
    android:id="@+id/lv2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

</LinearLayout>

【讨论】:

  • 我也使用这种方法 .. 发生的事情是我的主要活动有列表视图,并且它有项目点击监听器......我的导航抽屉有列表视图,它也有项目点击监听器....当我打开抽屉时 ....抽屉列表与主列表重叠,我最终单击主活动列表......抽屉列表永远不会获得焦点
  • 你是对的......它终于为我工作了......我没有按照你说的实现,我稍后更正了......她是我的代码
【解决方案2】:
<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" >

 <include layout="@layout/activity_main" />

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    android:focusable="true"/>
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"/>


</android.support.v4.widget.DrawerLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多