在安卓5.0之前是使用二维坐标来记录屏幕里的点,我们常用的width和height就是用来表示屏幕的z,y坐标。5.0之后开始加入三维坐标,除了x,y还另外增加了z来表示深度,也就是立体距离,这个z在安卓中用elevation
用两个有背景色的文本框来测试elevation的效果:
未使用elevation时的源代码:
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent"> 4 5 <TextView 6 android:layout_width="300px" 7 android:layout_height="300px" 8 android:layout_gravity="center" 9 android:background="#be2b2b" 10 11 /> 12 13 <TextView 14 android:layout_width="100px" 15 android:layout_height="100px" 16 android:layout_gravity="center" 17 android:background="#5abe2b" /> 18 19 20 </FrameLayout>
效果:小的文本框在大的文本框的上面
使用elevation后的源代码:带原代码的第一个文本框中加入
android:elevation="1px"
源代码:
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 > 5 6 <TextView 7 android:layout_width="300px" 8 android:layout_height="300px" 9 android:background="#be2b2b" 10 android:layout_gravity="center" 11 android:elevation="1px" 12 /> 13 14 <TextView 15 android:layout_width="100px" 16 android:layout_height="100px" 17 android:background="#5abe2b" 18 android:layout_gravity="center" 19 /> 20 21 22 </FrameLayout>
加入深度后的效果;
可以看到加了深度之后原本在上面的文本框被有深度的文本框覆盖