不能中心导航抽屉垂直项目 [英] Can't center Navigation Drawer items vertically

查看:184
本文介绍了不能中心导航抽屉垂直项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要业务布局(删除了不相关的元素):

Main activity layout (removed the irrelevant elements):

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"

    <RelativeLayout
        android:id="@+id/layout_relative_in_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black" >

        // some more elements ...

    </RelativeLayout>

    <ListView
        android:id="@+id/drawer_main"
        android:layout_width="120dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#80000000"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp" />

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

drawer_item.xml:

drawer_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerItemTextView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:layout_gravity="center"
    android:textColor="@android:color/white" >

</TextView>

列表项对齐到中心目前水平,而不是垂直方向。

The list items are aligned to the center horizontally now, but not vertically.

我应该怎么修改,以垂直居中呢?

What should i modify to center them vertically?

推荐答案

你的抽屉项目改成这样:

Change your drawer item to this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/frag1_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

然后尝试,这是为我工作。

then try, it is working for me.

这篇关于不能中心导航抽屉垂直项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆