You need to enable JavaScript to run this app. Android如何设计底部带数量标识的圆形购物车按钮
优惠活动
大模型
产品
解决方案
定价
更多

Android如何设计底部带数量标识的圆形购物车按钮

参考效果图

修正方案

你原布局的问题主要是数量容器没有设置对齐规则、小圆点和数字没有正确叠加,直接用下方修正后的代码即可实现效果:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:focusable="true">

    <!-- 底部主圆形购物车按钮 -->
    <FrameLayout
        android:layout_width="52dp"
        android:layout_height="52dp"
        android:layout_gravity="center"
        android:background="@drawable/circle_shape_filled"
        android:padding="15dp">

        <ImageView
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            app:srcCompat="@drawable/ic_baseline_shopping_cart"
            app:tint="@color/white" />

    </FrameLayout>

    <!-- 底部中央数量标识 -->
    <FrameLayout
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_gravity="center|bottom"
        android:background="@drawable/circle_shape_filled"
        android:layout_marginBottom="2dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textColor="@color/white"
            android:textSize="12sp"
            android:text="1" />
    </FrameLayout>

</FrameLayout>

补充说明

  • 数量标识的大小、距离底部的边距可以根据你的设计需求调整layout_width/layout_height和layout_marginBottom参数
  • 如果数字超过2位,可以适当调大数量容器的尺寸,或者把textSize改小适配

内容的提问来源于stack exchange,提问作者mephisour

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 12:45:07