Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “工具栏”子节点不居中_Android_Xml_Android Linearlayout_Toolbar - Fatal编程技术网

Android “工具栏”子节点不居中

Android “工具栏”子节点不居中,android,xml,android-linearlayout,toolbar,Android,Xml,Android Linearlayout,Toolbar,我很不好意思问这个问题,但我在这方面遇到了不少麻烦,似乎不明白为什么 也就是说,我试图将一个线性布局放在工具栏的中心,但就我的一生而言,我无法理解为什么它不起作用 有人能看到我在哪里犯的错误吗 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" x

我很不好意思问这个问题,但我在这方面遇到了不少麻烦,似乎不明白为什么

也就是说,我试图将一个线性布局放在工具栏的中心,但就我的一生而言,我无法理解为什么它不起作用

有人能看到我在哪里犯的错误吗

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize"
     android:background="@color/white"
     android:focusable="true"
     android:focusableInTouchMode="true"
     android:gravity="center"
     android:orientation="horizontal"
     android:id="@+id/toolbar">

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:layout_gravity="center">
</LinearLayout>

</android.support.v7.widget.Toolbar>


使用包装器视图将工具栏内的任何内容居中放置:

<android.support.v7.widget.Toolbar
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="?attr/actionBarSize"
 android:background="@color/white"
 android:focusable="true"
 android:focusableInTouchMode="true"
 android:gravity="center"
 android:orientation="horizontal"
 android:id="@+id/toolbar">

 <FrameLayout
  android:layout_height="match_parent"
  android:layout_width="match_parent">
    <TextView 
        text="Something"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
 </FrameLayout>

</android.support.v7.widget.Toolbar>

左侧插图是
工具栏的
内容插入开始
,具有默认维度。您可以使用xml设置为
0dp

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/white"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center"
    app:contentInsetStart="0dp"
    android:orientation="horizontal"
    android:id="@+id/toolbar">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </LinearLayout>

</android.support.v7.widget.Toolbar>

谢谢,我不知道左侧插入的工具栏有默认尺寸。