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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:52:07+00:00 2026-06-07T01:52:07+00:00

I am having an issue with using the Canvas to draw my Math equation

  • 0

I am having an issue with using the Canvas to draw my Math equation and text, and haivng text boxes at the bottom of the screen to input data for a result. On my current setup i can have either the buttons and text boxes, or the equation and variable names. Here is my code from the java class

    package com.soraingraven.suprRef;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class PerfectGasLaw extends Activity {
    class RenderView extends View {
        //For the Text
        Paint paint;
        Typeface font;

        //For the pics
        Bitmap PGL;

        public RenderView(Context context) {
            super(context);
            paint = new Paint();

            //Attempt to load the bitmaps
            try {               
                AssetManager assetManager = context.getAssets();
                InputStream inputStream = assetManager.open("PerfGasLaw.png");
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_4444;
                PGL = BitmapFactory.decodeStream(inputStream, null, options);
                inputStream.close();
                Log.d("BitmapText", "bobargb8888.png format: " + PGL.getConfig());

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                //we should really close our input streams here.
            }
        }

        //Drawing text and pics
        protected void onDraw(Canvas canvas) {
            paint.setColor(Color.BLUE);
            paint.setTypeface(font);
            paint.setTextSize(32);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.drawText("P = Pressure in Atmospheres", 25, 350, paint);
            canvas.drawText("V = Volume in Liters", 25, 400, paint);
            canvas.drawText("n = Number of moles", 25, 450, paint);
            canvas.drawText("R = Gas Constant", 25, 500, paint);
            canvas.drawText(" - (0.0821 Liter-Atmospheres / K / mole)", 50, 550, paint);
            canvas.drawText("T = Temperature in K", 25, 600, paint);
            canvas.drawText("If Constant Pressure - V1/V2 = T1/T2", 25, 650, paint);
            canvas.drawText("If Constant Temperature - P1/P2 = V2/V1", 25, 700, paint);
            canvas.drawText("If Constant Volume - P1/P2 = T1/T2", 25, 750, paint);

            canvas.drawBitmap(PGL, 25, 25, null);
            invalidate();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setContentView(new RenderView(this));
    }
}

And the 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="horizontal" >


    <EditText
        android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:ems="10"
        android:hint="@string/edit_message" >

        <requestFocus />
    </EditText>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="@string/button_send" />

</LinearLayout>

Please assist me in doing this. Also if anyone could tell me how to grab the input from a text field like this it would be helpful. Also I am attempting to do this using the least amount of XML possible.

  • 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-07T01:52:09+00:00Added an answer on June 7, 2026 at 1:52 am

    You can subclass your own, say EquationView from a View so that view has your onDraw method().

    Then in the XML you would place your view, like

    <mypackage.equation.EquationView ... 
      android:layout_width=...
      android:layout_height=...
    />
    

    along with those EditText and Button

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

Sidebar

Related Questions

I am having a issue using Google's SDC (Secure Data Connector) with my Google
I'm having strange issues with text on a canvas when using an iPhone or
I'm having an issue using the canvas.drawText() method. I have a custom view, as
I'm having difficulty using data created with canvas's todataurl() method. Currently my code sends
I'm having an issue using the Cookie class of the Servlet API 2.5 on
I'm having an issue using the qTip plugin with jQuery. I've created a js
I believe I am having a memory issue using numpy arrays. The following code
i'm having a little issue with doctrine using symfony 1.4 (I think it's using
I am having an issue with a website developed using ASP.Net/C# sometimes taking all
I am having an issue where I am using regex.Replace to replace part of

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.