【问题标题】:Android dynamic Bubbles on the view视图上的 Android 动态气泡
【发布时间】:2017-01-02 05:15:59
【问题描述】:

谁能在可点击的Android布局上制作动态气泡。

我的设计师想到的屏幕如下[![我所有的气泡都是分配给用户的一组任务。气泡的标签根据任务而变化][1]][1]

根据我的项目要求,颜色和半径将根据 api 响应发生变化。

您能否建议任何演示或示例。我用谷歌搜索了它,但我找不到这个答案。请指导我完成此操作。

【问题讨论】:

  • 没有内置任何东西。你必须从头开始做这一切。应该不会太糟糕 - 在 Canvas 上绘制圆圈非常容易。研究如何制作自定义视图。
  • @GabeSechan 你能推荐一些例子吗?
  • 你必须在画布上绘制所有视图。
  • @tpa 你能提供一些代码片段吗?

标签: android android-layout


【解决方案1】:

由于已经发布了一个答案,我也为您尝试过。希望你也能从这里得到一些帮助:

public class BubbleBackgroundDemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View view = new CustomView(this);
//        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(this.getWidth(),
//                ViewGroup.LayoutParams.MATCH_PARENT);
//        view.setLayoutParams(lp);


        setContentView(view);
    }

    public class CustomView extends View {

        private Paint paint;
        int screenWidth, screenHeight;



        public CustomView(Context context) {
            super(context);
            DisplayMetrics displaymetrics = new DisplayMetrics();

            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);


           screenWidth = displaymetrics.widthPixels;
             screenHeight = displaymetrics.heightPixels;

            // create the Paint and set its color
            paint = new Paint();
            paint.setColor(Color.GRAY);

        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.BLUE);
            canvas.drawCircle(200, 200, 100, paint);


            canvas.drawCircle(screenWidth-200, 200, 100, paint);

            canvas.drawCircle(screenWidth/2, screenHeight/2, 300, paint);

            canvas.drawCircle(screenWidth-200, screenHeight-200, 100, paint);

            canvas.drawCircle(200, screenHeight-200, 100, paint);

        }

    }

}

【讨论】:

  • 伟大的作品,完美的作品。然后我的另一个疑问是我如何在这个圈子上给出点击方法,并为同一个圈子提供不同的颜色?
【解决方案2】:

这是自定义圈子创建的方式,您可以参考各种链接在画布上动态创建圈子

public class CustomView extends View {

    private Paint paint;

    public CustomView(Context context) {
        super(context);

        // create the Paint and set its color        
        paint = new Paint();
        paint.setColor(Color.GRAY);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.BLUE);
        canvas.drawCircle(200, 200, 100, paint);
    }

}

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new CustomView(this));
    }

}

【讨论】:

  • 感谢您。你能指导我如何在项目中实现这个
  • 创建自定义视图,如 CustomView 创建构造函数并为位置 x、y 和半径传递参数。
  • 调用CustomView对象创建圆
  • @siddesh 我的另一个疑问是我如何在这个圈子上给出点击方法,并为同一个圈子提供不同的颜色?
猜你喜欢
  • 1970-01-01
  • 2014-04-02
  • 1970-01-01
  • 2013-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-26
  • 1970-01-01
相关资源
最近更新 更多