Ser*_*iev 11 android android-layout android-theme
无论布局结构如何,Button小部件都会绘制在任何其他小部件之上.当应用Material Dark/Light主题时,它在RelativeLayout和FrameLayout中重复.查看下面的屏幕截图,以更好地说明这种奇怪的行为.
检查Nexus 4和Nexus 5.但我怀疑它与设备有关.


Android 5.0 Lollipop和Material Design引入了新属性来指定小部件的高程(Z-index).这里描述.
要在按钮上绘制视图,可以添加android:elevation="1dp"到视图
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:elevation="1dp"
/>
Run Code Online (Sandbox Code Playgroud)
以下是早期回答误解问题的一部分,以供将来参考
使用RelativeLayout,您必须指定元素相对于其他元素的位置.
所以说你想要View在按钮下面,你必须添加id到元素并指定视图在按钮下面:
<Button
android:id="+id/myactivity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:layout_below="@id/myactivity_button"
/>
Run Code Online (Sandbox Code Playgroud)
查看针对RelativeLayout的Android开发人员指南和RelativeLayouts的可用LayoutParameters
FrameLayout通常不适合组织多个组件.FrameLayout旨在阻挡屏幕上的区域以显示单个项目.可以使用该android:layout_gravity属性控制FrameLayout子项的位置.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="Don't look so deep"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C00"
android:layout_gravity="bottom"
/>
Run Code Online (Sandbox Code Playgroud)
查看FrameLayout的Android文档以及layout_gravity的可用参数