Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6022949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:55:59+00:00 2026-05-23T03:55:59+00:00

My custom view does not display entirely. Please see my screenshot: And the source

  • 0

My custom view does not display entirely. Please see my screenshot:

enter image description here

And the source code

package com.dots;
import android.graphics.Color;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Dots1Activity extends Activity
{
    private static final String TAG = "DotsActivity";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);          


        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
             LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        CustomDrawableView view1 = new CustomDrawableView(this, 50, 50, Constants.DOTS_RADIUS, Constants.DOTS_COLOR);
        CustomDrawableView view2 = new CustomDrawableView(this, 150, 150, Constants.DOTS_RADIUS, Constants.DOTS_COLOR);
        CustomDrawableView view3 = new CustomDrawableView(this, 300, 300, Constants.DOTS_RADIUS, Constants.DOTS_COLOR);
        ll.addView(view1, layoutParams);
        ll.addView(view2, layoutParams);
        ll.addView(view3, layoutParams);
        setContentView(ll);
    }

}

class CustomDrawableView extends View implements View.OnClickListener{
    private Context context;
   private int x, y, radius, color;
   public CustomDrawableView(Context context, int x, int y, int radius, int color) {
       super(context);
       this.context = context;
       this.x = x;
       this.y =y;
       this.radius = radius;
       this.color = color;
       setOnClickListener(this);
   }

   protected void onDraw(Canvas canvas) 
   {
       super.onDraw(canvas);
       Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
       paint.setColor(color);
       canvas.drawCircle(x, y, radius, paint);
   }

   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
       super.onMeasure(View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2, View.MeasureSpec.EXACTLY),
               View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2, View.MeasureSpec.EXACTLY));
   }

   public void onClick(View v) {
       Toast.makeText(this.context, 
               x+"-"+y+"-"+radius, 
               Toast.LENGTH_SHORT).show();  
   }
}



public interface Constants 
{
    public static final int DOTS_RADIUS = 50;
    public static final int DOTS_COLOR = Color.GREEN;
    public static final int NUM_DOTS_ROWS = 5;
    public static final int NUM_DOTS_COLS = 5;
    public static final int WIDTH_BETWEEN_DOTS = 100;
    public static final int HEIGHT_BETWEEN_DOTS = 100;


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:56:00+00:00Added an answer on May 23, 2026 at 3:56 am

    Making the assumption that you don’t want the clipping you see in your screenshot. Your problem is that the values you return in onMeasure don’t account for your x, y offsets:

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2 + x, View.MeasureSpec.EXACTLY),
               View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2 + y, View.MeasureSpec.EXACTLY));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Custom map is broken on satellite view, does not show satellite imagery. Any ideas,
My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items
I want to display a small view that does not cover the whole screen
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I've created a custom view class and right now just want to draw an
I have a simple custom view that is connected via outlet to a NIB.
I want to write a custom view engine that returns custom text (like coma
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
My Drupal is displaying a simple custom view, with a nodelist. The trick is
how can i add a custom view to the right click menu of every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.