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 8265717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:54:09+00:00 2026-06-08T04:54:09+00:00

This is main.xml file, which is dividing the screen in two half. In bottom

  • 0

This is main.xml file, which is dividing the screen in two half. In bottom half, it is having Latitude and Longitude label and corresponding to each label, it has textbox that will show the current latitude and longitude value in the textbox.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@android:color/black" > 

    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:orientation="vertical" > 

        <!-- currently empty --> 

    </LinearLayout> 

    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:orientation="vertical" > 

        <LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:layout_weight="1" 
            android:orientation="horizontal" > 

            <!-- Latitude Label --> 

            <TextView 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:layout_weight="1" 
                android:text="Latitude" 
                android:textColor="#FFFFFF" /> 

            <EditText 
                android:id = "@+id/lat1"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_marginBottom="20dip" 
                android:layout_marginTop="5dip" 
                android:layout_weight="0.35" 
                android:singleLine="true" 
                android:textColor="#FFFFFF"
                /> 
        </LinearLayout> 

        <LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:layout_weight="1" 
            android:orientation="horizontal" > 

            <!-- Longitude Label --> 

            <TextView 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:layout_weight="1" 
                android:text="Longitude" 
                android:textColor="#FFFFFF" /> 

            <EditText 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_marginTop="5dip" 
                android:layout_weight="0.35" 
                android:singleLine="true" 
                android:textColor="#FFFFFF"
                android:id = "@+id/lat2" /> 
        </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 

But my question is- how I can draw a circle in the top half. Below is the example that I created in paint. I need to draw a circle using canvas in the top half. And the bottom half part is working for me fine.
enter image description here

I created another class file for drawing circle on the canvas-

public class DrawCanvasCircle extends View{
    public DrawCanvasCircle(Context mContext) {
        super(mContext);
    }
    protected void onDraw(Canvas canvas) { 
        super.onDraw(canvas); 
        Paint p = new Paint(); 
        p.setColor(Color.WHITE); 
        DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0); 

        p.setPathEffect(dashPath); 
        p.setStyle(Style.STROKE); 


        for (int i = 0; i < 7; i ++) { 
            canvas.drawCircle(100, 100, 50+(i*10), p); 
        } 


        invalidate(); 
    } 


}

And below is the main class, in which I am trying to add above canvas that I created in to the main class.

    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ll = (LinearLayout) findViewById(R.id.lc);
        DrawCanvasCircle pcc = new DrawCanvasCircle (this);
        Bitmap result = Bitmap.createBitmap(25, 25, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        pcc.draw(canvas);
        pcc.setLayoutParams(new LayoutParams(1000, 1000));
        ll.addView(pcc);
}

But it is not getting shown properly. Anything wrong I am doing.

  • 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-06-08T04:54:12+00:00Added an answer on June 8, 2026 at 4:54 am

    Change your customView class like

    public class DrawCanvasCircle extends View
    {
        Context context;
    
        public DrawCanvasCircle(Context mContext)
        {
            super(mContext);
            context = mContext;
        }
    
        protected void onDraw(Canvas canvas)
        {
            super.onDraw(canvas);
    
            Paint paint = new Paint();
            paint.setColor(0xFF0000);
            paint.setAlpha(255);
            paint.setStrokeWidth(2.0f);
            paint.setStyle(Paint.Style.STROKE);
            WindowManager mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
            int displayWidth = mWinMgr.getDefaultDisplay().getWidth();
            int displayHeight = mWinMgr.getDefaultDisplay().getHeight();
            int circleRadius = 100;
            canvas.drawCircle(displayWidth/2, displayHeight/4, circleRadius, paint);
            invalidate();
        }
    
    }
    

    and write below line of code into your onCreate method

    LinearLayout ll = (LinearLayout) findViewById(R.id.lc);
    DrawCanvasCircle pcc = new DrawCanvasCircle (this);
    ll.addView(pcc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm developing android in eclipse. i have a main.xml file which has a graphical
I have a GridView like this( main.xml ): <?xml version=1.0 encoding=utf-8?> <GridView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/gridView1
This code works well for displaying separate xml items in my main.xml. But is
my android app crash before load main.xml. This is the exception thrown java.lang.RuntimeException: Unable
My XML format is this : <Main> <IsD>false</IsD> <IsN>true</IsN> <ID>826e03b3-191c-40c9-8a3d-f6607842fa5f</ID> <ClientId>c6a32c38-0398-4806-b82f-e924f96217fa</ClientId> <General> <IsD>false</IsD> <IsN>true</IsN>
The main.xml file code: <TableRow android:id=@+id/TableRow01 android:layout_width=wrap_content android:layout_height=wrap_content> <TextView android:text=User android:id=@+id/TextView01 android:layout_width=wrap_content android:layout_height=wrap_content></TextView> <EditText
I have an xml file which I included as a resource in my netbeans
I have 2 xml files, a main file where I have a listView and
I have a listView, a main xml file and a customListview xml file. for
I have a site that loads in a XML file which tells where to

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.