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>
谢谢,我不知道左侧插入的工具栏有默认尺寸。