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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:22:26+00:00 2026-05-25T15:22:26+00:00

I have an existing xml layout and i am loading this layout in my

  • 0

I have an existing xml layout and i am loading this layout in my activity class. Now i want to draw a rectangle in this at bottom.Which on clicking would call new intent.How do i add this rectangle to my existing layout.

public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chart);

this the code to draw the graphics.. How do i achieve this?

drawView = new DrawView(this);
        drawView.setBackgroundColor(Color.WHITE);
        setContentView(drawView);
  • 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-25T15:22:27+00:00Added an answer on May 25, 2026 at 3:22 pm

    Activities have nothing to do with drawing UI (in any case they never do this directly). View classes are responsible for drawing.

    In your case you probably should extend Button class with your custom class. Override onMeasure() to make it square. And background will be anything you set it to be.


    A quick example:

    SquareButton.java:

    package com.inazaruk.helloworld;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.Button;
    
    public class SquareButton extends Button
    {
        public SquareButton(Context ctx)
        {
            super(ctx);
        }
    
        public SquareButton(Context ctx, AttributeSet attrs)
        {
            super(ctx, attrs);
        }
    
        public SquareButton(Context ctx, AttributeSet attrs, int defStyle)
        {
            super(ctx, attrs);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);           
    
            /* currently view is rectangle, so we get the shorter size 
             * and make it square. */
    
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
    
            width = height =(int) (Math.min(width, height));        
    
            super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
        }
    }
    

    Layout that uses this button main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:a="http://schemas.android.com/apk/res/android"
      a:orientation="vertical"   
      a:layout_width="fill_parent" 
      a:layout_height="fill_parent"
      a:gravity="center" 
      a:weightSum="1">
    
        <com.inazaruk.helloworld.SquareButton
            a:id="@+id/button"
            a:layout_height="0dp"
            a:layout_weight="0.5"         
            a:layout_width="fill_parent"        
            a:background="#ffffffff" 
            a:text="foo" 
            a:gravity="center"
            />
    
    </LinearLayout>
    

    Screenshot of result:
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an already existing XML request format corresponding to which I have to
TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
I have an existing class for serializing and deserializing objects to/from XML. It's a
I have an existing xml document with music playlist information, which is read into
i have a Question i want to add Child Element in My Existing Xml
I have several existing XML schema files with a defined data model. I would
I have an existing XML file that I would like to append without changing
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the
I have existing Linux shared object file (shared library) which has been stripped. I
I have the following layout in XML (splashscreen.xml): <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/frmLayout

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.