match_parent 不适用于内部布局的工具栏
match_parent not working for Toolbar with layout inside
android studio 2.0 beta5
我注意到,当我在工具栏中包含一个布局时,该布局的左边缘永远不会与工具栏父级的左边缘对齐,即使我已将两者都设置为 match_parent。
这是我的 xml 片段
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</android.support.v7.widget.Toolbar>
这是正在发生的事情的屏幕截图。
从上图可以看出,LinearLayout 与父级不匹配。我也尝试了 FrameLayout
和 RelativeLayout
以及相同的结果。
我不确定这是 android 工作室的错误还是左边的这个 space 是为某些东西保留的。
即使我 运行 应用程序在真实设备上也与父设备不匹配。
非常感谢任何建议
只要把android:contentInsetStart="0dp"放在里面:
<android.support.v7.widget.Toolbar....
contentInsetStart="0dp"
...</>
android studio 2.0 beta5
我注意到,当我在工具栏中包含一个布局时,该布局的左边缘永远不会与工具栏父级的左边缘对齐,即使我已将两者都设置为 match_parent。
这是我的 xml 片段
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</android.support.v7.widget.Toolbar>
这是正在发生的事情的屏幕截图。
从上图可以看出,LinearLayout 与父级不匹配。我也尝试了 FrameLayout
和 RelativeLayout
以及相同的结果。
我不确定这是 android 工作室的错误还是左边的这个 space 是为某些东西保留的。
即使我 运行 应用程序在真实设备上也与父设备不匹配。
非常感谢任何建议
只要把android:contentInsetStart="0dp"放在里面:
<android.support.v7.widget.Toolbar....
contentInsetStart="0dp"
...</>