Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android dynamic Bubbles on the view

Can anyone how to make dynamic bubble on the Android layout which is clickable.

My designer thought for the screen is below [![I the image all the bubble are some set of task assigned to the user.The label of bubble changes according to the task ][1]][1]

According to my project requirement the color and radius will change as per the api response.

Can you please suggest any demo or example. I googled it but i cant find the answer for this. Please guide me to accomplish this .

like image 840
Pranav MS Avatar asked Aug 03 '26 08:08

Pranav MS


1 Answers

As one answer is already posted, I also tried for you. Hope you get some help from here too :

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);

        }

    }

}
like image 143
EminenT Avatar answered Aug 05 '26 23:08

EminenT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!