• android 圆角效果


    最近做一个效果,要一个上边两个角为圆角,下面两个角为直角的四边形白色背景;

    如下图:

    image

    这里用到了shape属性中的corners 属性,

    api原文中是这样:

    <corners 
        android:radius="integer" 
        android:topLeftRadius="integer" 
        android:topRightRadius="integer" 
        android:bottomLeftRadius="integer" 
        android:bottomRightRadius="integer" />

    单一设置android:radius="integer"时,表示四个角都为integer像素的圆角;

    这里我开始的时候这样设置了四个属性

    <corners android:topLeftRadius="10px" 
            android:topRightRadius="10px" android:bottomLeftRadius="0px" 
            android:bottomRightRadius="0px"/>

    结果发现四个角无圆角效果,怎么找都找不到原因;

    后来我想到了折中的办法,我这样设置:

    <corners android:topLeftRadius="10px" 
            android:topRightRadius="10px" android:bottomLeftRadius="1px" 
            android:bottomRightRadius="1px"/>

    下面的两个角我都给1个像素的圆角效果,这样在手机上根本看不出来有圆角效果;

    做出来的效果如下:

    image

    源代码如下:在drawable文件夹下,建whiterounded_half_bg.xml文件,文件内容为:

    <?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        <solid android:color="#FFFFFFFF" /> 
        <corners android:topLeftRadius="10px" 
            android:topRightRadius="10px" android:bottomLeftRadius="1px" 
            android:bottomRightRadius="1px"/> 
        <padding android:left="0dp" android:top="0dp" android:right="0dp" 
            android:bottom="0dp" /> 
    </shape>

    然后在layout文件夹下,相应的页面中相应的位置下使用android:background="@drawable/whiterounded_half_bg"


    转自:http://henzil.easymorse.com/?p=214

  • 相关阅读:
    编译原理笔记 2
    编译原理笔记 1
    初步学习计算机图形学 [闫令琪]
    复杂 Web 前端的设计
    使用 GitHub Actions 部署 .Net 5 程序
    ES 2020 Optional Chain (可选链)
    2020 Web 前端学习记录
    WPF TreeView 支持多选
    linux (CentOS 7)报错:yum 命令报错 “ Cannot find a valid baseurl for repo: base/7/x86_6 ”
    node.js 报错
  • 原文地址:https://www.cnblogs.com/shanzei/p/2421242.html
Copyright © 2020-2023  润新知