Fin*_*ner 29
原来FrameLayout就是我想要的.只需在您的布局中执行此操作:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.proj.MyView
android:id="@+id/board1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<com.proj.MyView
android:id="@+id/board2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
虽然你可以在API 21及更高版本中使用RelativeLayout和实现分层FrameLayout,但事情已经发生了变化.
在API 21及更高版本中,xml的后期子节点并不意味着它将与早期的子节点重叠.相反,它用于Elevation确定哪个视图将与其他视图重叠(Z-Index).
例如,如果你有这样的东西.
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:text="Hello World"
android:layout_gravity="top" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@android:color/black"
android:layout_gravity="bottom" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
该View不会是即使它之后添加可见Button.那是因为Button海拔高于View.要重新排列Z-Index,您可以elevation向各个视图添加属性.
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:text="Hello World"
android:layout_gravity="top"
android:elevation="0dp" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@android:color/black"
android:layout_gravity="bottom"
android:elevation="2dp" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
这种方式View会重叠Button.
有关高程和阴影的更多信息:https://material.io/guidelines/material-design/elevation-shadows.html
| 归档时间: |
|
| 查看次数: |
20099 次 |
| 最近记录: |