0

Canvasを使用して数学の方程式とテキストを描画し、画面の下部にテキストボックスを表示して結果のデータを入力することに問題があります。現在の設定では、ボタンとテキストボックス、または方程式と変数名のいずれかを使用できます。これがJavaクラスの私のコードです

    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));
    }
}

そして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>

これを行うのを手伝ってください。また、誰かがこのようなテキストフィールドから入力を取得する方法を教えてくれるなら、それは役に立ちます。また、可能な限り最小限のXMLを使用してこれを実行しようとしています。

4

1 に答える 1

1

ビューにonDrawメソッド()が含まれるようにEquationView、たとえば、独自のサブクラスを作成できます。View

次に、XMLで、次のようにビューを配置します。

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

EditTextそれらと一緒にButton

于 2012-07-05T16:22:36.993 に答える