前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Android开发中常见的优惠券样式实现和需要注意的细节

Android开发中常见的优惠券样式实现和需要注意的细节

作者头像
yechaoa
发布于 2022-06-10 04:58:47
发布于 2022-06-10 04:58:47
67200
代码可运行
举报
文章被收录于专栏:移动开发专栏移动开发专栏
运行总次数:0
代码可运行

效果图

主要是中间的两个半圆和虚线的实现,其他都比较简单。但是其中也会涉及到一些细节性的东西,后面讲。

item布局

整体分为三部分:左边、中间、右边,即以虚线为分割。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/dp_6"
    android:layout_marginLeft="@dimen/dp_10"
    android:layout_marginRight="@dimen/dp_10"
    android:layout_marginTop="@dimen/dp_6"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="@dimen/dp_10"
    app:cardElevation="@dimen/dp_0"
    app:contentPadding="@dimen/dp_0">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:orientation="vertical"
            android:padding="@dimen/dp_10">

            <TextView
                android:id="@+id/tv_coupon_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:maxLines="1"
                android:text="@string/text"
                android:textColor="@color/red"
                android:textSize="@dimen/sp_20"
                android:textStyle="normal"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dp_10"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="领取人数/次数"
                        android:textColor="@color/textGray"
                        android:textSize="@dimen/sp_12"/>

                    <TextView
                        android:id="@+id/tv_coupon_customer_and_all"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/dp_10"
                        android:text="@string/text"
                        android:textColor="@color/black"
                        android:textSize="@dimen/sp_12"/>

                </LinearLayout>

                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/dp_20"
                    android:layout_marginRight="@dimen/dp_20"
                    android:background="@color/gray"/>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="已使用"
                        android:textColor="@color/textGray"
                        android:textSize="@dimen/sp_12"/>

                    <TextView
                        android:id="@+id/tv_coupon_sumNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/dp_10"
                        android:text="@string/text"
                        android:textColor="@color/black"
                        android:textSize="@dimen/sp_12"/>

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:gravity="center"
            android:orientation="vertical">

            <View
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:background="@drawable/shape_bg_semi_circle_top"/>

            <View
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="@drawable/shape_bg_dotted_line"
                android:layerType="software"/>

            <View
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:background="@drawable/shape_bg_semi_circle_bottom"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3.5"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="@dimen/dp_10">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:baselineAligned="false"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/dp_2"
                    android:text="¥ "
                    android:textColor="@color/red"
                    android:textSize="@dimen/sp_16"/>

                <TextView
                    android:id="@+id/tv_coupon_faceValue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/text"
                    android:textColor="@color/red"
                    android:textSize="@dimen/sp_20"
                    android:textStyle="bold"/>

            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dp_10"
                android:text="截止日期"
                android:textColor="@color/black"
                android:textSize="@dimen/sp_12"/>

            <TextView
                android:id="@+id/tv_coupon_end_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/dp_10"
                android:text="@string/text"
                android:textColor="@color/black"
                android:textSize="@dimen/sp_12"/>

        </LinearLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

半圆和虚线的实现

这里都是用shape的方式完成的。

  • shape_bg_semi_circle_top.xml
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid
        android:color="@color/bgGreen"/>
    <corners
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp"
        android:bottomLeftRadius="16dp"
        android:bottomRightRadius="16dp"/>

</shape>
  • shape_bg_semi_circle_bottom.xml
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <solid
        android:color="@color/bgGreen"/>
    <corners
        android:topLeftRadius="16dp"
        android:topRightRadius="16dp"
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"/>

</shape>
  • shape_bg_dotted_line.xml
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="90"
        android:toDegrees="90">
    <shape
        android:shape="line">
        <stroke
            android:width="1dp"
            android:color="#ff9999"
            android:dashGap="5dp"
            android:dashWidth="5dp"/>
    </shape>
</rotate>

其中需要注意的细节

  • 金额数值与 ¥ 的显示对齐问题,这个地方涉及到基准线的知识点, 在LinearLayout中,默认是底部对齐的,只需要设置LinearLayoutandroid:baselineAligned属性为false 就行了,这样就是以顶部对齐。但是因为TextView默认是有一点padding的,所以显示 ¥ 的textview又marginTop了2dp,这样看起来顶部会在同一水平线。
  • 最外层用的是CardView,效果图中看起来还是蛮不错的,但是在5.0以下,CardView显示内部会有留白,那两个半圆就会显示在白色的背景之内,极其影响美观,所以就可以根据5.0为分水岭做一个判断,具体可查看解决CardView在5.0以下留白的问题
  • 半圆的背景色要与整体的背景色保持一致。
  • 虚线其实是水平方向的,android:fromDegrees=”90”,android:toDegrees=”90”,旋转了90度就变成了竖线。
  • 使用虚线的控件还要添加android:layerType="software" 属性,否则会是实线。
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-07-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Android 天气APP(二十二)改动些许UI、增加更多空气质量数据和生活建议数据展示
这篇文章接着上一篇来写的,主要是增加更多空气质量的数据展示和更多生活建议数据的展示。
晨曦_LLW
2020/09/25
6230
Android:超好用的ScrollView,滑动操作最简单的方式
上篇博客试图采用RecyclerView这个组件来实现一个滑动效果,结果发现大部分代码都是通过java代码来控制填充,设计时不仅操作麻烦(最主要看不懂),而且不能像xml文件一样实时预览效果。 碰巧发现了这篇博客 Android ListView滚动条配置完全解析,详细介绍了ScrollView这个组件的相关配置,非常清楚。我利用ScrollView实现了所需要的目标。(仅用xml,无需java逻辑)
zstar
2022/06/14
1.9K0
Android:超好用的ScrollView,滑动操作最简单的方式
Android 天气APP(十七)热门城市 - 国内城市
在上一篇做了国外的热门城市数据的展示,这一篇就简单一些,增加国内的热门城市。 效果图
晨曦_LLW
2020/09/25
7880
android listview 滑动卡顿问题解决
之前在使用listview进行每次通知一来,根据判断是否有这个标志,就更新listview所绑定的数据源,通知更新priceAd.notifyDataSetChanged();,也用了网上的建议使用viewHolder进行listview的item复用机制,但还是会出现卡顿的现象,经过分析,原来是listview的item布局嵌套太多,导致刷新的时候,重绘过多,造成卡顿的现象,以下是另一片博客的分析贴出来,大家讨论感谢这位前辈:http://blog.csdn.net/knighttools/article/details/18259485:
全栈程序员站长
2022/09/15
9990
Android如何制作漂亮的自适布局的键盘
  最近做了个自定义键盘,但面对不同分辨率的机型其中数字键盘不能根据界面大小自已铺满,但又不能每种机型都做一套吧,所以要做成自适应,那这里主讲思路。   这里最上面的titlebar高度固定,下面输入的金额高度也固定(当然也可以自适应),主要是中间的数字键盘,高度和宽度需要自适应。   最常见的解决方案是用线性布局,自适应当然是按比例,但布局中无%的概念,那就要用到layout_weight了,该属性的作用是决定控件在其父布局中的显示权重(具体概念就不多说了)。   这里用一个LinearLayout 将
欢醉
2018/01/22
1.2K0
Android如何制作漂亮的自适布局的键盘
Android 天气APP(二十五)地图天气(下)嵌套滑动布局渲染天气数据
上篇文章中,完成了对地图的控制,那么这篇文章中完成对天气数据的渲染。 完成这篇文章实现的效果如下,如果你觉得不行那就可以不用看下面了。
晨曦_LLW
2020/09/25
2K0
Android订票系统订票功能实现(特效点击按钮实现票数自动加减1)
要实现的效果是点击加按钮就购买分数自动加一,同时计算合计的总计 先共享一份colors.xml的数据,比较全面,可以根据需要添加 <?xml version="1.0" encoding="UTF-8
SmileNicky
2019/01/17
2.1K0
Android 天气APP(五)天气预报、生活指数的数据请求与渲染
天气预报是预测未来几天的天气,常用列表显示,实现这个功能的业务逻辑是:访问API、获取返回值、列表配置、数据渲染。首先是API接口。
晨曦_LLW
2020/09/25
1.6K0
Android  天气APP(五)天气预报、生活指数的数据请求与渲染
Android 天气APP(二十三)增加灾害预警、优化主页面UI
天气预报光有普通天气总感觉好少了点什么,所以和风天气给补上了,那就是灾害天气的预警,灾害预警API可以获取指定城市的极端天气预警数据。
晨曦_LLW
2020/09/25
5190
Android 天气APP(二十三)增加灾害预警、优化主页面UI
Android 天气APP(十六)热门城市 - 海外城市
反正国内的天气也做好了,不妨做一下做一下国外的天气,国外的天气数据的展示,我将重新设计一套UI,区别于国内的天气UI,开搞~
晨曦_LLW
2020/09/25
1.2K0
强烈建议!让你的团队强制推行ConstraintLayout!
ConstraintLayout(约束布局)在2016年的Google I/O大会上就推出来了,经历这两年的迭代,功能已经非常的成熟了。一次偶然的机会,在项目中尝试了使用约束布局,从此被它的功能所深深折服。它能很轻易的将你从使用层层的嵌套去实现复杂的布局中解放出来。使用ConstraintLayout后基本可以抛弃LinearLayout和RelativeLayout的使用。完全不需要任何嵌套就可以实现复杂的UI,使用起来特别清爽。所以相信我,使用过就会爱上它。
吴延宝
2018/10/18
9630
强烈建议!让你的团队强制推行ConstraintLayout!
Android企业级实战-界面篇-2
前几天发表了此系列第一篇文章,比较受欢迎,一天涨的粉丝盖过一年的了,在粉丝的私信下,今天将第二篇赶出来,效果图结合第一篇展示,废话不多说,直接开始
计蒙不吃鱼
2025/06/12
530
Android企业级实战-界面篇-2
Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151784.html原文链接:https://javaforall.cn
全栈程序员站长
2022/06/24
7700
Android物联网应用程序开发(智慧园区)—— 设置传感器阈值对话框界面
RecyclerView零点突破(基本使用篇)
一直以为自己是会用RecyclerView的,但现在感觉只是刚入门而已 本文以仿几个生活常见的界面来演示RecyclerView 本系列分为3篇: RecyclerView零点突破(基本使用篇)
张风捷特烈
2018/12/24
8740
Android实习收获:UI细节bug引发的layout_weight深入理解
- button1会占据2/3的位置,button2会占据1/3. - 注意,两个Button的宽度都是0dp
张拭心 shixinzhang
2022/11/30
4200
相关推荐
Android 天气APP(二十二)改动些许UI、增加更多空气质量数据和生活建议数据展示
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验