Android 导航抽屉内的水平居中项目
我有以下导航抽屉菜单设置: 主布局活动\u Main.xml:Android 导航抽屉内的水平居中项目,android,xml,navigation-drawer,Android,Xml,Navigation Drawer,我有以下导航抽屉菜单设置: 主布局活动\u Main.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:t
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true"
android:theme="@style/NavigationViewStyle"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" >
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/nav_profile"
app:actionLayout="@layout/menu_item"
android:title=""/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:src="@drawable/menu_icon"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu Title"
android:textSize="16sp"
android:textColor="@color/white"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
相反,我希望它水平居中,我做错了什么?我已经尝试了许多关于自定义布局的重力(menu_item.xml)以及项目的修复,但似乎没有任何效果
我不知道菜单中的app:actionLayout
是否可以居中,如果不能,请告诉我如何正确地使项目与我想要的对齐。
提前感谢。试试这个,menu item.xml您可以将重心设置为水平中心。试试这个
menu_item.xml
希望这有助于更新答案,请看一看,并让我知道它是否有效。请更具体一点?我指定了bro。我尝试了这个,结果很混乱,请注意我的NavigationDrawableView的宽度限制为150dp。@Anas你能上传新的屏幕截图吗?,我可以帮助您进行更改。我在项目布局中添加了填充,现在它看起来居中了
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="center|center_horizontal"
android:src="@drawable/menu_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image_view"
android:layout_gravity="center_horizontal|center"
android:gravity="center"
android:text="Menu Title"
android:textColor="@color/white"
android:textSize="16sp" />
</RelativeLayout>