Android_长方形_白色背景灰色边框背景

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <solid android:color="#f4f6f9" />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item android:bottom="1.75dp"
        android:left="1.75dp"
        android:right="1.75dp"
        android:top="1.75dp">
        <shape android:shape="rectangle">
            <solid android:color="#f1f1f1" />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item android:bottom="2.5dp"
        android:left="2.5dp"
        android:right="2.5dp"
        android:top="2.5dp">
        <shape android:shape="rectangle">
            <solid android:color="#dfdfdf" />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item
        android:bottom="3dp"
        android:left="3dp"
        android:right="3dp"
        android:top="3dp">
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="3dp" />

        </shape>
    </item>
</layer-list>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个Android长方形色盘的实现方法: 1.在res/drawable文件夹下创建一个selector.xml文件,代码如下: ```xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false"> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#FFD2D2" /> <corners android:radius="1dp"/> <gradient android:angle="0" android:startColor="#FF3333" android:endColor="#F8F8F8" android:type="linear" /> </shape> </item> </selector> ``` 2.在布局文件中添加自定义的RectangleColorSelectorView,代码如下: ```xml <com.example.colorselfdefinedemo.RectangleColorSelectorView android:id="@+id/self_view" android:layout_width="fill_parent" android:layout_height="wrap_content" /> ``` 3.创建RectangleColorSelectorView类并继承View类,代码如下: ```java public class RectangleColorSelectorView extends View { private Paint mPaint; private int mWidth; private int mHeight; public RectangleColorSelectorView(Context context) { super(context); init(); } public RectangleColorSelectorView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public RectangleColorSelectorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mWidth = getWidth(); mHeight = getHeight(); LinearGradient linearGradient = new LinearGradient(0, 0, mWidth, 0, new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED}, null, Shader.TileMode.CLAMP); mPaint.setShader(linearGradient); canvas.drawRect(0, 0, mWidth, mHeight, mPaint); } } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值