简体   繁体   English

导航抽屉非常宽

[英]Navigation Drawer is very wide

I have implemented Navigation drawer similar to Android Sliding Menu using Navigation Drawer . 我已经使用Navigation Drawer实现了类似于Android Sliding Menu的Navigation抽屉 The slide menu is coming up properly, but very wide (The width is very long).. When I check it in my Phone/TAB it is very long both portrait and landscape mode. 幻灯片菜单可以正确显示,但是非常宽(宽度很长)。.在电话/ TAB中查看时,纵向和横向模式都非常长。 It is almost touching the other side of the screen. 它几乎要碰触屏幕的另一侧。 Something like a full screen. 像全屏一样。

When I run the project given in AndroidHive. 当我运行AndroidHive中给出的项目时。 Things are fine. 一切都很好。 I have just tuned the XML to by requirements that is all 我刚刚按照所有要求将XML调整为

Here is the drawer list XML: 这是抽屉列表XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="@drawable/list_selector" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="25dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:contentDescription="@string/desc_list_item_icon"
    android:src="@drawable/maps" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/icon"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:paddingRight="40dp"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/list_item_title" />

<TextView
    android:id="@+id/counter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="8dp"
    android:background="@drawable/roundcircle"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="4dp"
    android:textColor="@color/counter_text_color"
    android:textStyle="bold" />

 </RelativeLayout>

This is ListView.XML which has the Slide ListView 这是具有幻灯片ListView的ListView.XML

<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/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/list_background"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

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

I am not sure where I am going wrong? 我不确定我要去哪里错了?

The ListView needs to have a smaller width. ListView需要具有较小的宽度。 Try android:layout_width="240dp" . 尝试android:layout_width="240dp"

This is basically based on the official guide: http://developer.android.com/training/implementing-navigation/nav-drawer.html 这基本上是基于官方指南: http : //developer.android.com/training/implementing-navigation/nav-drawer.html

My tip: Double check tutorials with official documentation :) 我的提示:仔细检查带有官方文档的教程:)

You have not specified a proper width for your NavigationDrawer . 您尚未为NavigationDrawer指定适当的宽度。 If you set the width to match_parent it will - as the name implies - be as big as the parent. 如果将宽度设置为match_parent ,则其名称将与父项一样大-顾名思义。 And you don't want the NavigationDrawer to be as big as the screen, so specify a width of about 240dp . 而且您不希望NavigationDrawer像屏幕一样大,因此请指定大约240dp的宽度。 Try something like this: 尝试这样的事情:

<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/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:layout_gravity="start"
        android:background="@color/list_background"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM