android里面layer-list中的inset和clip到底有什么作用

来源:互联网 发布:广东奥飞数据科技ipo 编辑:程序博客网 时间:2024/04/28 07:00
Inset Drawable:用于通过指定的间距把图片插入到XML中,它在View需要比自身小的背景时常用。有些像padding的作用。例子:  第一步:drawable文件中建立inset_drawable.xml  <?xml version="1.0" encoding="utf-8"?>  <inset  xmlns:android="http://schemas。android。com/apk/res/android"  android:drawable="@drawable/photo2"  android:insetTop="100dp"  android:insetRight="100dp"  android:insetBottom="200dp"  android:insetLeft="100dp" />  第二部,在xml中引用  <LinearLayout xmlns:android="http://schemas。android。com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:background="@drawable/inset_drawable">  Clip Drawable:可以剪载图片显示,例如,可以通过它来做进度度。你可以选择是从水平或垂直方向剪载。其中的gravity设置从整个部件的哪里开始。例子:  第一步,在drawable文件中建立:clip_drawable.xml  <?xml version="1.0" encoding="utf-8"?>  <clip xmlns:android="http://schemas。android。com/apk/res/android"  android:drawable="@drawable/test_img"  android:clipOrientation="horizontal"  android:gravity="left" />  第二步,在ImageView中引用:  <LinearLayout xmlns:android="http://schemas。android。com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">  <ImageView  android:id="@+id/clipimage"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:src="@drawable/clip_drawable"/>  </LinearLayout>  Dev Guide中在ImageView中设置的是android:background="@drawable/clip_drawable",但是我使用background的时,会在程序中报空指针的错误。  最后,使用程序控制:  ImageView imageView=(ImageView)findViewById(R.id.clipimage);  ClipDrawable clipDrawable=(ClipDrawable)imageView.getDrawable();  clipDrawable.setLevel(5000);  level的值为0到10000 。当值为10000时图全部显示。
0 0
原创粉丝点击