android - 工具栏内不允许相对布局

标签 android android-layout android-toolbar android-relativelayout

我正面临奇怪的警告,试图自定义工具栏外观。我将 RelativeLayout 放在 android.support.v7.widget.Toolbar 中以重新组织 Toolbar。在模拟器和设备上一切正常并按预期显示。唯一的问题是 .xml 文件中出现烦人的警告,如下所示:

screenshot of the warning

问题是实际问题是什么,它如何损害我的应用程序以及我如何解决此警告。据我所知,Toolbar 的行为与 ViewGroup 相同,为什么不允许 RelativeLayout 成为它的子项? 谢谢。

最佳答案

ToolbarViewGroup 延伸和 RelativeLayout's也是。

我已经在 Android Studio 1.5.1 上试过了,但我看不出这个问题。

<android.support.v7.widget.Toolbar
                android:id="@+id/toolBar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <RelativeLayout
                    android:id="@+id/toolBarTv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textSize="18dp">
                </RelativeLayout>

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

您应该能够将您的 Android Studio 更新到最新版本或检查您是否使用过时的 Platform,然后您只需要更新那个 Platform 到最后一个版本。

然后它就不会出现了。或者它可能会在下一次更新中修复。

关于android - 工具栏内不允许相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34992766/

相关文章:

android - 共享首选项不会立即应用

android - 由于 NullPointerException 无法启动 Activity

android - 如何用自定义可绘制对象替换 Android 工具栏上用于 ActionBarToggle 的汉堡包图标?

java - android中的activity需要Handler吗?

android - 如何显示离散 slider 的刻度线?

android - 在布局绑定(bind)中使用属性资源 (?attr/)?

android - 工具栏 - 左重力未找到抽屉 View

android - 设备方向的陀螺仪问题

android - 用于旋转相机 Intent 捕获的图像的代码在 Android 中不起作用

android - 如何从新的 Lollipop 工具栏中删除膨胀的菜单/项目?