Android-资源
来源:互联网 发布:nginx www域名重定向 编辑:程序博客网 时间:2024/06/14 20:47
一、什么是资源?
所谓资源都是指在res文件夹下的xml文件,每一种类型的xml文件都对应了一种资源
二、外形资源(shape)
1、shape资源用于定义一个基本的几个图形(矩形,圆形,线条等)
2、属性android:shape 取值(rectangle 矩形,oval椭圆,line直线,ring圆环)
3、子节点
3.1 <corners/>定义几何图形四个角度的弧度
android:radius 设置四个角的弧度
android:xxxradius 设置某一个角的弧度
3.2<gradient/>定义使用渐变颜色填充
android:startColor 开始颜色
android:centerColor 中间颜色
android:endColor结束颜色
android:angle 方向角度(取值必须是45的整倍数)(0从左到右,90从上到下)
android:type 渐变类型(取值:liear 线性渐变,radial径向渐变)(一定要指定android:gradientRadius属性)
3.3<padding/>定义几何形状的内边距
3.4<size/>定义几何形状的大小
3.5<solid/>定义使用单种颜色填充 android:color
3.6<stroke/>定义几何形状的边框
①android:with 边框的高度
②android:color 边框的颜色
③android:dashWidth 虚线的宽度
④android:dashGap 虚线的间距
实例:
代码:
布局文件:
<?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" > <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:layout_width="match_parent" android:layout_height="50dp" android:paddingLeft="100dp" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true" android:background="@drawable/et_selector" android:hint="请输入用户名" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="6dp" android:gravity="center" android:text="用户名:" android:drawableLeft="@drawable/icon_user" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:clickable="true" android:focusable="true" android:background="@drawable/et_selector" android:hint="请输入密码" > <EditText android:layout_width="wrap_content" android:layout_height="50dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="6dp" android:gravity="center" android:text=" 密码:" android:drawableLeft="@drawable/icon_user" /> </FrameLayout> </LinearLayout>
选择器:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/et_shape1"> </item> <item android:state_focused="false" android:drawable="@drawable/et_shape"> </item></selector>
状态一:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!--设置背景颜色--> <solid android:color="#ff0000"> </solid> <!--设置边框--> <stroke android:width="2dp" android:color="#ff00ea" ></stroke><!--设置边框弧度--><corners android:topLeftRadius="10dp" android:bottomLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="10dp" ></corners></shape>
状态二:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!--设置背景颜色--> <solid android:color="#00ffee"></solid> <!--设置边框--> <stroke android:width="2dp" android:color="#00ff00"></stroke> <!--设置边框弧度--> <corners android:topLeftRadius="10dp" android:bottomLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="10dp" ></corners></shape>
三、尺寸资源(Dimension)
1、dimen标签用于定义尺寸资源
2、<dimen name=""><dimen>
四、颜色资源(Color)
1、color标签用于定义尺寸资源
2、<color name=""></color>
- Android资源
- android资源
- android资源
- android 资源
- Android资源
- Android 资源
- android资源
- Android 资源
- Android资源
- Android资源
- Android资源
- Android资源
- android资源
- Android资源
- Android 资源
- Android资源
- android 资源
- android资源
- 前端知识体系
- 阿里云上安装Nginx及反向代理配置
- Java中final与static final的区别
- android手势冲突解决(二)
- windows系统下查看数据库端口
- Android-资源
- Effective Java读书笔记二六(Java Tips.Day.26)
- 一个好的决策案例
- spring整合quartz实现定时任务
- 前端资源教程
- 在使用 classification_report 中出现IndexError错误
- C++实验13
- 常用算法
- spring boot了解