android物流进度展示

本文介绍了一个自定义的Android视图`LogisticsView`,用于展示物流进度。通过设置节点间隔、边距和适配器数据,该视图能够绘制出包含时间轴和节点的物流状态更新。代码中详细展示了如何在`onDraw`方法中绘制线条、圆点、文字,并处理文字换行。此外,还提供了`MainActivity`示例来说明如何使用`LogisticsView`并填充数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

闲来没事,对别人的的物流进度展示轴进行重构,先看看效果


下面是主要代码 一个自定义View
public class LogisticsView extends View {

    float width;
    float nodeRadius;

    Paint paint;

    Context context;

    /**
     * 节点间隔
     */
    int nodeDistance;

    /**
     * 边距
     */
    int left = 40;
    int top = 30;

    int dWidth;
    int dHeight;


    public LogisticsView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public LogisticsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LogisticsView);
        width = typedArray.getDimension(R.styleable.LogisticsView_width, 5);
        nodeRadius = typedArray.getDimension(R.styleable.LogisticsView_nodeRadius, 6);
        init();
    }

    public LogisticsView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(getResources().getColor(R.color.colorAccent));
        paint.setAntiAlias(true);

        nodeDistance = Dp2pxUtils.dip2px(context, 80);

        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

        dWidth = wm.getDefaultDisplay().getWidth();
        dHeight = wm.getDefaultDisplay().getHeight();
    }

    LogisticsAdapter logisticsAdapte

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值