我正面临奇怪的警告,试图自定义工具栏外观。我将 RelativeLayout
放在 android.support.v7.widget.Toolbar
中以重新组织 Toolbar
。在模拟器和设备上一切正常并按预期显示。唯一的问题是 .xml 文件中出现烦人的警告,如下所示:
问题是实际问题是什么,它如何损害我的应用程序以及我如何解决此警告。据我所知,Toolbar
的行为与 ViewGroup
相同,为什么不允许 RelativeLayout
成为它的子项?
谢谢。
最佳答案
Toolbar
从 ViewGroup
延伸和 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/