Elevation
例子表示视图控件所在的高度,值越大对应的阴影越大,看起来高度越高
###TranslationZ
同样表示视图控件所在的高度,但是其表示的是相对高度
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context="com.zxl.test_elevation.MainActivity"> <FrameLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:orIEntation="horizontal" androID:background="#3f51b5" androID:elevation="2dp"> linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:orIEntation="horizontal"> linearLayout> linearLayout> <TextVIEw androID:ID="@+ID/tv" androID:layout_wIDth="80dp" androID:layout_height="48dp" androID:gravity="center" androID:layout_gravity="center" androID:text="test" androID:background="#448aff" androID:elevation="6dp"/> FrameLayout>linearLayout>
public class MainActivity extends AppCompatActivity { private TextVIEw tv; private boolean isSelected = false; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); tv = findVIEwByID(R.ID.tv); tv.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { if(!isSelected){ isSelected = true; tv.setTranslationZ(6); System.out.println("zxl--->0--->"+tv.getElevation()+"--->"+tv.getTranslationZ()); }else{ isSelected = false; tv.setTranslationZ(-6); System.out.println("zxl--->1--->"+tv.getElevation()+"--->"+tv.getTranslationZ()); } } }); }}说明
01-23 14:53:23.620 7029-7029/com.zxl.test_elevation I/System.out: zxl--->0--->6.0--->6.0 01-23 14:53:30.678 7029-7029/com.zxl.test_elevation I/System.out: zxl--->1--->6.0--->-6.0
总结从程序运行后log可以看出
视图控件的整个高度值是Elevation+TranslationZ,当其值为0时则没有阴影了,当其值小于0在在上一个控件下方,当其值大于0则有阴影,从而出现高度。
以上是内存溢出为你收集整理的Android的Elevation与TranslationZ探索全部内容,希望文章能够帮你解决Android的Elevation与TranslationZ探索所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)