InsetDrawable

作者: 难得糊涂与君勉 | 来源:发表于2018-01-11 15:14 被阅读162次
    总结.png

    其他Draw文章参考:
    Android中Drawable整体介绍

    前言

    谈可以将其他Drawable内嵌到自己当中。 当View需要一个小于View的实际边界的背景时使用。
    对应于<inset>标签,它可以将其他Drawable内嵌到自己中,并且可以留出一定的间距。当view希望自己的背景比自己的实际区域小的时候,可以采用。

    语法

    <?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>

    定义插入可绘制对象。这必须是根元素。
    属性:
    xmlns:android
    字符串。必备。定义 XML 命名空间,其必须是 "http://schemas.android.com/apk/res/android"。

    android:drawable
    可绘制对象资源。必备。引用要插入的可绘制对象资源。

    android:insetTop
    尺寸。顶部插入,表示为尺寸值或尺寸资源

    android:insetRight
    尺寸。右边插入,表示为尺寸值或尺寸资源

    android:insetBottom
    尺寸。底部插入,表示为尺寸值或尺寸资源

    android:insetLeft
    尺寸。左边插入,表示为尺寸值或尺寸资源

    实例

    <?xml version="1.0" encoding="utf-8"?>
    <inset xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/red_drawable"
        android:insetTop="10dp"
           android:insetRight="10dp"
        >
    </inset>
    

    XML中:这里放两个TextView进行对比

      
        <TextView
            android:layout_width="match_parent"
            android:layout_height="49dp"
            android:background="#fdff"/>
        
        <TextView
            android:layout_width="match_parent"
            android:layout_height="49dp"
            android:background="@drawable/inset_darawable"/>
    

    效果图:


    image.png

    相关文章

      网友评论

        本文标题:InsetDrawable

        本文链接:https://www.haomeiwen.com/subject/rzaznxtx.html