Android 设置bitmap、selector、shape

来源:互联网 发布:52kkm软件下载 编辑:程序博客网 时间:2024/05/22 00:34

在android中描述 形容(加载处理)图片 是通过 Bitmap这个类来操作

      <?xml version="1.0" encoding="utf-8"?>      <bitmap xmlns:android="http://schemas.android.com/apk/res/android"      android:src="@mipmap/welcome_bg"     android:tileMode="disabled">     </bitmap>  src 是用来加载 图片   tileMode 是加载的方式     值为 disabled  (默认值) 根据加载图片的屏幕大小动态进行缩放     值为 clamp  当图片大于加载的屏幕或者是控件的大小的时候,会对其进行 裁剪(从左上角开始)                当图片小于加载 的屏幕或者是控件的大小的时候 ,其他空白的地方会以图片边缘的颜色来填充    值为 repeat 图片会重复填充界面    值为 mirror 图片会以镜像的形式重复填充界面    android:antialias="true" 设置加载模式为抗锯齿   android:dither="true"    设置加载模式为 防抖动

selector((背景)选择器)

      :Selector主要是用来改变ListView和Button控件的默认背景        <!-- 默认 显示 的背景图-->    <item android:drawable="@drawable/bg_normal"/>       <!-- 按下 显示 的背景图-->    <item android:drawable="@drawable/bg_press"   android:state_focused="true" android:state_pressed="true"/>    <item android:drawable="@drawable/bg_press" android:state_pressed="true"/>    *** item 相当于大容器中的 一个小的容器 ,也是用来放东西的。

shape的属性:

    每个状态(item)都对应着一个效果,shape是用来定义形状的(画图),以下为shape的一些常见属性:     android:shape=   "rectangle" | "oval" | "line" | "ring"                        画矩形        画圆     画直线    画圆环      * 设置 大小                           <size                  android:width="10dp"  android:height="10dp" />        * 设置颜色    <solid                  android:color="color" />        * 设置圆角    <corners                    半径        android:radius="4dp"                     左边上部半径        android:topLeftRadius="4dp"                  右边上部半径        android:topRightRadius="4dp"                  左边下部半径        android:bottomLeftRadius="4dp"                 右边下部半径        android:bottomRightRadius="4dp" />        *设置边框(描边)    stroke描边 android:width="2dp" 描边的宽度,android:color 描边的颜色。     <!--下面两个参数是 把边框变成虚线用-->    把描边弄成虚线的形式,设置方式为: android:dashWidth="5dp" android:dashGap="3dp"    dashGap 虚线中空格的长度      dashWidth 虚线中实线的长度(android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。)        <stroke         android:width="2dp"                  android:color="#fff"                  android:dashWidth="5dp"                  android:dashGap="3dp" />      * 设置渐变颜色    gradient:渐变 android:startColor和android:endColor分别为起始和结束颜色,android:centerColor 为中间颜色,    android:angle是渐变角度,必须为45的整数倍。当angle=0时,渐变色是从左向 右。然后逆时针方向转,当angle=90时为从下往上。    . linear 线性渐变, 就是颜色从左往右, 从下往上    . radial 放射渐变, 例如: 从一个圆中心到圆的边缘变化    . sweep 扫描式渐变, 类似雷达扫描的那种图形    gradientRadius 和android:type=”radial”一起连用, 配置shape图片的半径        android:useLevel   是否水平        android:centerX="integer"    android:centerY="integer"   中心指定位置坐标x y轴       <gradient                  android:angle="45"                  android:centerX="integer"                  android:centerY="integer"         android:startColor="#fff"        android:centerColor="#fff"                  android:endColor="#fff"        android:gradientRadius="integer"         android:type=["linear" | "radial" | "sweep"]                  android:useLevel=["true" | "false"] />           <padding          android:bottom="30dp"          android:left="30dp"          android:right="30dp"          android:top="30dp"/>    padding标签   作用: 设置控件中(文字)内容与shape图片边框的距离   bottom 距离底部距离   left 距离左边距离   right距离 右边距离    top 距离顶部距离