android ----在xml里面绘制

一 Bitmap  的使用

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
     android:src="@drawable/ic_launcher_foreground"/>

可以直接把图片转换成Bitmap 类型

二 shape的使用

通过shape可以在xml中绘制各种形状

1 shape的属性讲解

<?xml version="1.0" encoding="utf-8"?>
<!--默认为rectangle-->
<!--android:shape=["rectangle|line|oval|ring]-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
    >
    <!--当shape ="rectangle"时使用半径,会被后面的当个半径属性覆盖,默认为1dp-->
    <corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer"
        />
<!-渐变-->
<gradient 
  android:angle ="integer"
  android:centerX ="integer"
  android:centerY ="integer"
android:centerColor="integer"
android:endColor ="color"
android:gradientRadius ="integer"
android:startColor ="color"
android:type=[linear|radial|sweep]
android:useLevel=[true|false]
/>
<!--内边距-->
<padding android:left ="integer"
  android:top ="integer"
android:right="integer"
android:bottom="integer"
/>
    <size android:width="integer"
        android:height="integer" />
    <!--填充颜色-->
    <solid android:color="color"/>
    
    <!--指定边框-->
    <!--dashWidth 虚线宽度-->
    <!--dashGap 虚线间隔宽度-->
        
    <stroke android:color="color"
        android:width="integer"
        android:dashGap="integer"
        android:dashWidth="integer" />
</shape> 
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="5dp" />

    <gradient
        android:startColor="#ff5da2ff"
        android:endColor="#805fbbff"
        android:angle="45"
        />
    <padding android:left="5dp"
        android:top="7dp"
        android:right="8dp"
        android:bottom="8dp"
        />

</shape>

三 Layer 的使用

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    
    >
    <item android:drawable="@drawable/ic_launcher_background"
        tools:ignore="ResourceCycle" />
    <item android:drawable="@drawable/ic_launcher_background"
        android:left="20dp"
        android:top="20dp"
        android:right="20dp"
        android:bottom="20dp"
        />
    
    
</layer-list>

四 selector 的使用

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <!--默认时背景图片-->
    <item android:drawable ="@drawable/a" />
    <!--没有焦点时的背景图片-->
    <item android:state_focused="false"  android:drawable ="@drawable/b" />

    <!--非触摸模式下获得焦点并单击时的背景图片-->
    <item android:state_focused="true" android:state_pressed="true"
        android:drawable="@drawable/c" />

    <!--触摸模式下单击时的背景图片-->
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/d" />
    <!--选中时的背景图片-->
    <item android:state_selected="true" android:drawable="@drawable/e" />

    <!--获取焦点时的照片-->
    <item android:state_focused="true" android:drawable="@drawable/f" />
</selector>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值