Android 如何在导航抽屉中将自定义布局居中?
我创建了一个导航抽屉并列出了菜单图标。之后,我不得不在菜单列表的底部添加一个自定义布局 活动\u main.xmlAndroid 如何在导航抽屉中将自定义布局居中?,android,navigation-drawer,Android,Navigation Drawer,我创建了一个导航抽屉并列出了菜单图标。之后,我不得不在菜单列表的底部添加一个自定义布局 活动\u main.xml <?xml version="1.0" encoding="utf-8"?> <!-- Use DrawerLayout as root container for activity --> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:layout_gravity="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
ndroid:layout_height="?attr/actionBarSize"
app:titleTextColor="@color/white"
android:background="?attr/colorPrimary"
ndroid:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_view_menu"
app:headerLayout="@layout/nav_header"/>
</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">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_prof"
android:title="@string/my_profile" />
........other items here.......
</group>
<group android:checkableBehavior="single">
<item app:actionLayout="@layout/toggle_button"
android:title="@string/blank"
/>
</group>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/left_rounded"
android:backgroundTint="@color/red"
android:text="@string/lang_en"
android:textColor="@color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/right_rounded"
android:text="@string/lang_ar" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginBottom="@dimen/margin_medium"
android:layout_gravity="bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/left_rounded"
android:backgroundTint="@color/red"
android:text="@string/lang_en"
android:textColor="@color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/right_rounded"
android:text="@string/lang_ar" />
</LinearLayout>
在互联网上做了一些研究之后,我想出了一个解决方案
步骤
在NavigationView布局中包括我的自定义布局(toggle_button.xml)李>
导航视图布局
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:layout_gravity="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
ndroid:layout_height="?attr/actionBarSize"
app:titleTextColor="@color/white"
android:background="?attr/colorPrimary"
ndroid:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</FrameLayout>
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_view_menu"
app:headerLayout="@layout/nav_header">
<include layout="toggle_button.xml""/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
张贴您的抽屉布局文件的代码,使用布局XML更新您仍然没有提供@Sam要求的内容。您的导航布局文件在哪里?@H.Brooks请现在检查,更新的问题sotoggle_按钮
是您要在中心显示的自定义布局吗?