• Android 之形状Drawable


      形状Drawable资源允许使用 <shape>标记指定基本形状的尺寸、背景、轮廓线,从而定义这些基本形状。

    每个形状都包含一个类型(通过shape属性指定)、定义该形状尺寸的属性,以及指定内边距、笔画和背景色的值。

    shape属性的值:

    (1)line 一条跨越了父View的宽度的水平线。

    (2)oval 简单的椭圆形。

    (3)rectangle 简单的矩形。也支持使用radius属性创建圆角矩形的<corners>子节点。

    (4)ring 支持使用innerRadius和thicknessRatio将园环形状的内径和厚度。

    例1:圆角Button

    drawable(新建一个资源文件夹)/shape_btn.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle">
        <solid android:color="#FF6600"/>
        <corners android:radius="10dp"/>
    </shape>

    activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="15dp">
        
        <Button 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="圆角按钮"
            android:background="@drawable/shape_btn"/>
    
    </RelativeLayout>

    效果:

    例2:椭圆按钮

    shape_btn.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="oval">
        <solid android:color="#FF6600"/>
    </shape>

    activity_main.xml

    <Button 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="椭圆按钮"
            android:background="@drawable/shape_btn"/>

    效果:

    -----------------------------------------------------------------

    有时我们需要一条横线,这个简单可以使用TextView实现:

    <TextView 
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="#FF6600"/>

  • 相关阅读:
    International Collegiate Programming Contest 2019 Latin American Regional Contests E. Eggfruit Cake(思维/尺取)
    Codeforces Round #673 (Div. 2) C. k-Amazing Numbers(思维)
    2020 计蒜之道 预赛 第一场 A、B
    生成字符画
    我对目前国内教学的看法
    Stm32 调试时发生HardFault_Handler
    python异常处理
    windows nfs客户端配置
    linux服务器删除文件后df -h查看文件系统占比无变化
    python ssh小程序
  • 原文地址:https://www.cnblogs.com/yshyee/p/3373821.html
Copyright © 2020-2023  润新知