一款很炫的自定义卡片控件(A beautiful gift Cards for Android)

这是一款很炫的自定卡片控件,能够运用于电商类app下单操作,支持自定义多种属性,A beautiful gift Cards for Android!

国际案例:有图有真相

动态效果图

效果图

使用方法:
  • 注意:
    使用 [Android Studio 2.2 Preview 5]以上才支持下面compile,以下可删掉
com.android.tools.build:gradle:2.2.0-alpha5
com.android.support.constraint:constraint-layout:1.0.0-alpha3
  • Gradle
compile 'com.ldoublem.GiftCard:giftcardlib:0.3'
  • Or download the libray for your module:
示例:

布局文件xml

 <com.ldoblem.giftcardlib.GiftCardView
                android:layout_width="300dp"
                android:layout_height="200dp"
                card:bgStartColor="#11cd6e"
                card:buyButtonColor="#11cd6e"
                card:cardBgColor="#33475f"
                card:buttonByText="购买"
                card:cardGiftTitle="礼物卡"
                card:cardGiftLogo="@mipmap/ic_launcher"
                card:buttonCheckText="确定"
                card:checkButtonColor="#2c2c2c"
                card:bgPackColor="#56abe4"
                card:priceTextColor="#fff"/>

java文件

 mGiftCardView = (GiftCardView) findViewById(R.id.gc_shop);
        mGiftCardView.setMTitle("苹果礼券");
        mGiftCardView.setMPrice(188);
        mGiftCardView.setButtonBuyText("买");
        mGiftCardView.setButtonCheckText("确定");
        mGiftCardView.setCardTip("请检查你的购物单");
        mGiftCardView.setCardBgColor(Color.BLACK);
        mGiftCardView.setGiftLogo(R.mipmap.ic_launcher);
        mGiftCardView.setBgStartColor(Color.BLACK);
        mGiftCardView.setBgEndColor(Color.BLACK);
        mGiftCardView.setBuyButtonColor(Color.BLACK);
        mGiftCardView.setCheckButtonColor(Color.BLACK);
        mGiftCardView.setPriceTextColor(Color.BLACK);
        mGiftCardView.setBgPackBgColor(Color.BLACK);
        mGiftCardView.setOnCheckOut(new GiftCardView.Buyer("陆先生", "中国浙江省",
                        "杭州市,西湖区,南山路 100 号", "有效期:3 天"),
                new GiftCardView.OnCheckOut() {
                    @Override
                    public void Ok(int vid) {
![shot1.png](http://upload-images.jianshu.io/upload_images/1964096-ee724b9716f4be0c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

                    }
                })

献上源码GiftCard,感谢作者huxq17

更多精彩文章请关注微信公众号”Android经验分享“:这里将长期为您分享Android高手经验、中外开源项目、源码解析、框架设计和Android好文推荐!
扫一扫加我哦

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,关于 Android 自定义进度条控件的实现,我可以为您提供一些思路和示例代码。 首先,我们需要继承自 View 或者 ProgressBar,然后在 onDraw 方法中实现自己的绘制逻辑。具体来说,需要绘制背景、进度条和文本等内容。 示例代码如下: ```java public class CustomProgressBar extends ProgressBar { private Paint mPaint; private String mText; private Rect mRect; public CustomProgressBar(Context context) { super(context); init(); } public CustomProgressBar(Context context, AttributeSet attrs) { super(context, attrs); init(); } public CustomProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { mPaint = new Paint(); mPaint.setAntiAlias(true); mRect = new Rect(); } @Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); // 绘制背景 mPaint.setColor(Color.GRAY); mPaint.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); // 绘制进度条 mPaint.setColor(Color.BLUE); mPaint.setStyle(Paint.Style.FILL); float progress = getProgress() * 1.0f / getMax(); canvas.drawRect(0, 0, getWidth() * progress, getHeight(), mPaint); // 绘制文本 mPaint.setColor(Color.WHITE); mPaint.setTextSize(24); mText = getProgress() + "%"; mPaint.getTextBounds(mText, 0, mText.length(), mRect); float x = getWidth() / 2f - mRect.centerX(); float y = getHeight() / 2f - mRect.centerY(); canvas.drawText(mText, x, y, mPaint); } } ``` 这个自定义控件实现了一个简单的水平进度条,包括了背景、进度条和文本三个部分。当然,您可以根据自己的需求进行更改和扩展。 希望这个示例代码能够帮助到您,如果您还有其他问题,欢迎继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值