【问题标题】:Draw custom shape android绘制自定义形状android
【发布时间】:2018-04-06 18:51:36
【问题描述】:

我想绘制一个自定义形状,用作进度条。

关于如何创建它的任何提示? (示例如下)

我只知道如何做圆圈、甜甜圈和酒吧。 =/

【问题讨论】:

标签: android progress-bar draw shape


【解决方案1】:

您可以通过使用 Progressbar 扩展来创建自定义形状

试试这个代码,根据你的需要定制

public class CustomBar extends ProgressBar {

 

        Paint p = new Paint();

        int progress;

        public CustomBar(Context context) {

                super(context);

                p.setColor(Color.GREEN);

        }



@Override
protected synchronized void onDraw(Canvas canvas) {

                canvas.drawLine(0, 0, getWidth(), 0, p);

                canvas.drawLine(0, 0, 0, getHeight(), p);

                canvas.drawArc(new Rect(0, 0, getWidth(),  getHeight()), 40, true, p);

                /**

                 * Whatever drawing is needed for your Layout

                 * But make sure you use relative lenghts and heights

                 * So you can reuse your Widget.

                 * Also use the Progress Variable to draw the filled part

                 * corresponding to getMax()

                 */

        }

}  

更多详情请查看以下链接

https://pastebin.com/pKhK3YCa

【讨论】:

    猜你喜欢
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    相关资源
    最近更新 更多