Android知识点6-shape布局

shape标签,用好了,可以是你的界面遍的美观大气上档次

转载请标注出处:http://blog.csdn.net/Bingsman/article/details/48251663

先来张图看看效果:

效果不错

来看看代码吧:
1-shape代码,例如shape_image如下:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- 实心 -->

    <solid android:color="@android:color/white" />
    <!-- 渐变 -->
    <gradient
        android:angle="270"
        android:endColor="#FFFFFF"
        android:startColor="#000000" />
    <!-- 描边 -->

    <stroke
        android:width="0.5dp"
        android:color="#B1B1B1" />
    <!-- 圆角 -->

    <corners
        android:bottomLeftRadius="50dp"
        android:bottomRightRadius="50dp"
        android:topLeftRadius="50dp"
        android:topRightRadius="50dp" />

    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />

</shape>

2-主布局代码如下:
以Image为例子效果就是第三个图中的第三个

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:background="@layout/shape_image"
        android:src="@drawable/ic_launcher" />

最后详细讲解一下shape标签下的这几个属性
solid:实心,就是填充的意思
android:color指定填充的颜色

gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type=”linear”,即线性渐变,可以指定渐变为径向渐变,android:type=”radial”,径向渐变需要指定半径android:gradientRadius=”50”。

stroke:描边
android:width=”1dp” 描边的宽度,android:color 描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth=”3dp”
android:dashGap=”2dp”
其中android:dashWidth表示’-‘这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
android:radius为角的弧度,值越大角越圆。
我们还可以把四个角设定成不同的角度,方法为:

<corners 
        android:topRightRadius="20dp"    
        android:bottomLeftRadius="20dp"   
        android:topLeftRadius="0dp"    
        android:bottomRightRadius="0dp"    
 />

这里有个地方需要注意,bottomLeftRadius是右下角,而不是左下角。

padding:间隔

源码点击下载

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

记住我的名字啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值