zoukankan      html  css  js  c++  java
  • 《第一行代码》阅读笔记(十六)——Shape

    在Android开发中,我们可以使用shape定义各种各样的形状,也可以定义一些图片资源。相对于传统图片来说,使用shape可以减少资源占用,减少安装包大小,还能够很好地适配不同尺寸的手机。
    不多说,直接上一个简单的案例:
    在drawble文件定义shape_round_corner.xml

    <?xml version="1.0" encoding="utf-8"?><!--    //定义四个圆角-->
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#ff00" />
        <corners
            android:bottomLeftRadius="12dp"
            android:bottomRightRadius="12dp"
            android:topLeftRadius="12dp"
            android:topRightRadius="12dp" />
        <stroke
            android:width="1dp"
            android:color="#ff0" />
    </shape>
    
    

    在需要的时候直接通过背景属性引入即可。

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="15dp"
            android:layout_weight="5"
            android:background="@drawable/shape_round_corner">
        </RelativeLayout>
    

    渐变案例

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
        <corners android:radius="30dp" />
    
        <gradient
            android:angle="180"
            android:endColor="#42B0E9"
            android:gradientRadius="50%p"
            android:startColor="#467FE5"
            android:type="linear" />
    </shape>
    
    

    效果

    参考文件
    Android shape属性大全

  • 相关阅读:
    Poj 2391 二分答案+最大流+拆点
    POJ 1087 A Plug for UNIX 最大流
    POJ 1459 Power Network 最大流
    POJ 2112 Optimal Milking 二分答案+最大流
    POJ 1273 Drainage Ditches 最大流
    POJ 1149 PIGS 最大流
    POJ 2288 Islands and Bridges 哈密尔顿路 状态压缩DP
    The Cow Lexicon
    1523. K-inversions
    1350. Canteen
  • 原文地址:https://www.cnblogs.com/zllk/p/13369681.html
Copyright © 2011-2022 走看看