shape的基本使用

2017-12-28  本文已影响5人  努力深耕Android的小透明

    shape与selector相似 ,都在drawable 目录下/ ,可以设置为edittext的backgroud/src .

shape的使用步骤:

  1. res/drawable 新建xml(命名可以shape开头)
  2. xml文件编写
1.<?xml version="1.0" encoding="utf-8"?>
2.<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    android:shape=["rectangle"(矩形) | "oval"(椭圆) | "line"(线性) | "ring"(环形) >

    <gradient
4.    <!-- 渐变色 -->
6.        android:angle="180"
7. //角度  可以改变  ,尽量是45度的倍数
8.        android:centerColor="#0f0"
9.        android:endColor="#00f"
10.        android:startColor="#f00" />


11.    <!-- 内边距 -->
12.    <padding
13.        android:bottom="7dp"
14.        android:left="7dp"
15.        android:right="7dp"
16.        android:top="7dp" />


17.    <!-- 设置圆角  半径越大 圆角越大-->
18.    <corners android:radius="8dp" />


19.    <!-- 填充色 -->
20.    <solid android:color="#FEFED7" />


21.//描边设置直线与虚线
22.    <stroke
23.        android:dashGap="1dp"  //空格的宽度
24.        android:dashWidth="3dp" //实线的宽度
25.        android:width="1dp"  //线的宽度
26.        android:color="#6BB2D6" />
27.
28.<!--     设置最小宽高  10dp  10dp -->
29.    <size android:width="10dp" android:height="48dp"/>
30.
31.</shape>
  1. 使用
    android:background="@drawable/shape_location_edittext"
上一篇 下一篇

猜你喜欢

热点阅读