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

  • Home
  • SEARCH
  • 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 7832127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:03:24+00:00 2026-06-02T12:03:24+00:00

I have a class named SeatsPanel where I draw seats (using drawRect) in the

  • 0

I have a class named SeatsPanel where I draw seats (using drawRect) in the onDraw method. The onDraw method uses Canvas as a parameter, but how do you set size of the Canvas? The reason why I’m asking this question is because this class is being inflated in another class. I know that the canvas has the default height and width of the phone, but I need to make it smaller. How can I do this?

Any help would be appreciated.

  • 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-02T12:03:25+00:00Added an answer on June 2, 2026 at 12:03 pm

    I’ve tried to implement a simple application that draws a black rect within the main activity, that is drawn pushing a button. For example, in the MainActivity:

        private Button button1;
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button1=(Button)findViewById(R.id.button);
        button1.setOnClickListener(new OnClickListener(){
    
                public void onClick(View v) {
                 switch(v.getId()){
                    case R.id.button:
    
                         LinearLayout ll=(LinearLayout)findViewById(R.id.linearLayout1);
                         System.out.println(ll.getWidth()+" "+ll.getHeight());
                         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ll.getWidth(),ll.getHeight());
                         YourView yourView = new YourView(getBaseContext());
                         yourView.setBackgroundColor(Color.WHITE);
                         ll.addView(yourView,params);
                        break;
                 }
    
            }
    
        });
    
    }
    

    And in the YourView class:

        private Bitmap savedBitmap;
    public YourView(Context context) {
        super(context);
    }
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        System.out.println(canvas.getWidth()+" "+canvas.getHeight());
    
        Paint textPaint = new Paint();
        textPaint.setARGB(255, 0, 0, 0);
        textPaint.setTextAlign(Paint.Align.RIGHT);
        textPaint.setTextSize(11);
        textPaint.setTypeface(Typeface.DEFAULT);
    
        canvas.drawColor(Color.WHITE);
        System.out.println(canvas.getWidth());
        System.out.println(canvas.getHeight());
    
        canvas.drawRect(200, 20, 500, 100, textPaint);
    }
    

    The main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Push the button and draw a Rect" />
    
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
    
    
    
    
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    </LinearLayout>
    

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

Sidebar

Related Questions

I have a class named Entry declared like this: class Entry{ string Id {get;set;}
I have a class named Particle which has a std::set as a member. The
I have a class named Product in class library project. I am using SubSonic
I have set my frame in my main named Main class. And now, I
I have data-set represented as latitude-longitude and a VALUE(named class) associated with each latitude-longitude
I have a class named 'Material' The class itself represents an effect, but instances
i have class named Group i tried to test configuration: var cfg = new
I have a class named baseClass. From this class I inherit a class names
I have a Class named Constants that contains all the constant variable in my
I have a class named Person and in this class is the property PersonName

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.