android shape 自定义形状 属性

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014624241/article/details/80335781

1.ui情况

一个按钮,被一个圆环套着;一般,就是直接让人家切;可以不切呢;
这里写图片描述
其实,通用的方法;自己写shape
代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    android:shape="rectangle">
    <!--设置圆角渐变颜色-->
    <!--<gradient android:startColor="#FFFF0000"
    android:endColor="#80FF00FF"
    android:angle="270" />-->
    <!--设置内容离边界的距离-->
    <!-- <padding
         android:left="10dp"
         android:right="10dp"
         android:top="10dp"
     android:bottom="10dp" />-->
  <!--  &lt;!&ndash;设置填充颜色&ndash;&gt;
    <solid android:color="@color/white" />-->
    <!--设置描边颜色-->
      <stroke android:width="2.0dip"
      android:color="#e7e7e7"
      android:dashWidth="3.0dip"
      android:dashGap="0.0dip" />
    <!--设置圆角-->
    <corners
        android:bottomLeftRadius="26.5dp"
        android:bottomRightRadius="26.5dp"
        android:topLeftRadius="26.5dp"
        android:topRightRadius="26.5dp" />

</shape>

布局里写这个效果,代码如下:

  <ImageButton
                    android:id="@+id/imgbtn_collect"
                    android:layout_width="54dp"
                    android:layout_height="54dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="@dimen/base35dp"
                    android:background="@drawable/shape_4_circle26"
                    android:src="@mipmap/ic_river_collect" />

2.复习 阴影 填充 描边

solid:实心,就是填充的意思
android:color指定填充的颜色

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

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

corners:圆角
android:radius为角的弧度,值越大角越圆。

猜你喜欢

转载自blog.csdn.net/u014624241/article/details/80335781