您的位置:首页 > 移动开发 > Android开发

Android Drawable - Inset Drawable使用详解(附图)

2016-05-24 00:33 591 查看
一个可以让Drawable内嵌到自己View当中, 并且可以设置Drawable到View边缘之间的边距, 当然LayerDrawable也可以办到

资源放置位置:

  Eclipse/AS: res/drawable/filename.xml

引用用法:

  In Java: R.drawable.filename

  In XML: @drawable/filename

语法:

<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:insetTop="dimension"
android:insetRight="dimension"
android:insetBottom="dimension"
android:insetLeft="dimension" />


首个标签必须是inset;

android:drawable: Drawable资源引用;

android:insetTop: Drawable距离View顶部边缘的距离;

android:insetRight: Drawable距离View右边边缘的距离;

android:insetBottom: Drawable距离View底部边缘的距离;

android:insetLeft: Drawable距离View左边边缘的距离;

example:



布局XML代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!--Inset Drawable-->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/inset_drawable"
android:gravity="center"
android:text="Inset Drawable"
android:textAllCaps="false"/>
</LinearLayout>


inset_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/img"
android:insetBottom="20dip"
android:insetLeft="20dip"
android:insetRight="20dip"
android:insetTop="20dip"/>


img.xml(shape图片)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00ffff"/>
</shape>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: