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
语法:
首个标签必须是inset;
android:drawable: Drawable资源引用;
android:insetTop: Drawable距离View顶部边缘的距离;
android:insetRight: Drawable距离View右边边缘的距离;
android:insetBottom: Drawable距离View底部边缘的距离;
android:insetLeft: Drawable距离View左边边缘的距离;
example:
布局XML代码:
inset_drawable.xml
img.xml(shape图片)
资源放置位置:
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>
相关文章推荐
- android之context(上下文)、五大布局
- android开发笔记之Gson解析
- AsyncTask - 基本原理 图文剖析
- android事件处理-基于监听机制
- android端webview js alert对话框--不能弹出--解决办法
- Android configChanges的配置项详解
- Android系统为什么要分层实现?
- 使用编译时注解方式实现View注入(Android Studio)
- Android DrawerLayout 侧滑菜单栏
- Android RxJava使用介绍(二) RxJava的操作符
- Java+Android实现DES与四种模式、AES、MD5算法三合一
- ViewDragHelper源码分析
- android开发笔记之Json解析
- Android三级图片缓存
- [Android]Android开源工具项目集合20160523
- 关于handler机制(结合源码及方法的调用去总结)
- android源码解析(二十七)-->HOME事件流程
- 第一个Android crackme(2016-05)
- Android-architecture之MVC、MVP、MVVM、Data-Binding
- Android RxJava使用介绍(一)概念