Ich habe Probleme beim Festlegen von Ansichten, die in einem DrawerLayout zentriert werden sollen. Das DrawerLayout ist auf links eingestellt. Ich möchte die Innenansicht in die Mitte stellen, aber sie erscheinen immer nach links. Wie kann ich es schaffen? Bitte helfen sie aus. Danke vielmals. Hier sind die Layout-XML.So legen Sie fest, dass layout_gravity in LinearLayout in einem DrawerLayout angezeigt wird
main_layout.xml
<!--<android.support.v4.widget.DrawerLayout-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include layout="@layout/custom_toolbar"/>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- The main content view -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_marginLeft="-64dp"
android:layout_gravity="start"
android:name="com.onandroid.hplus.ui.navigationdrawer.NavigationDrawerFragment"
tools:layout="@layout/form_new" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
form_add.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_device_code"
android:textColorHint="@color/text"
android:drawableLeft="@drawable/ic_bar_code_white_24"
android:drawableRight="@mipmap/ic_action_refresh"
android:enabled="false"
android:layout_gravity="center_horizontal"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_device_locale"
android:layout_gravity="center"
android:textColorHint="@color/text"
android:drawableLeft="@drawable/ic_location_white_24"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_device_name"
android:layout_gravity="center"
android:textColorHint="@color/text"
android:drawableLeft="@drawable/ic_abc_white_24"
/>
<LinearLayout
android:layout_width="200dp"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/bt_form_ok"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/bt_form_cancle"/>
</LinearLayout>
</LinearLayout>