How to drawline on drawable in xml

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

How to drawline on drawable in xml

Postby l3_o_O_lvl » Mon Feb 13, 2012 4:17 pm

Help Me Pleas

OscillosFinActivity.java
Code: Select all
package osc.fin;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class OscillosFinActivity extends Activity {
    public  Paint paint;
    public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
       paint = new Paint();
       //setContentView(R.layout.main);
       setContentView(new Panel(this));
    }
   class Panel extends View {
       public Panel(Context context){
       super(context);
    }
       public void onDraw(Canvas canvas){
          float w = this.getWidth();
          float h = this.getHeight();
          paint = new Paint();
          paint.setColor(Color.WHITE);
          paint.setAntiAlias(true);
          canvas.drawRect(0,0,w,h, paint);
          paint.setColor(Color.LTGRAY);
          paint.setStrokeWidth(2);
          
          canvas.drawLine(128,h,128,0, paint);   //แนวตั้ง//
          canvas.drawLine(256,h,256,0, paint);
          canvas.drawLine(384,h,384,0, paint);
          canvas.drawLine(512,h,512,0, paint);
          canvas.drawLine(640,h,640,0, paint);
          canvas.drawLine(768,h,768,0, paint);
          canvas.drawLine(896,h,896,0, paint);
          canvas.drawLine(1024,h,1024,0, paint);
          canvas.drawLine(1152,h,1152,0, paint);
          
          canvas.drawLine(w,70,0,70, paint);      //แนวนอน//
          canvas.drawLine(w,140,0,140, paint);
          canvas.drawLine(w,210,0,210, paint);
          canvas.drawLine(w,280,0,280, paint);
          canvas.drawLine(w,350,0,350, paint);
          canvas.drawLine(w,420,0,420, paint);
          canvas.drawLine(w,490,0,490, paint);
          canvas.drawLine(w,560,0,560, paint);
          canvas.drawLine(w,630,0,630, paint);
          
          canvas.drawLine(635,14,645,14, paint);//1 ตั้ง
          canvas.drawLine(635,28,645,28, paint);
          canvas.drawLine(635,42,645,42, paint);
          canvas.drawLine(635,56,645,56, paint);
          
          canvas.drawLine(635,84,645,84, paint);//2  ตั้ง
          canvas.drawLine(635,98,645,98, paint);
          canvas.drawLine(635,112,645,112, paint);
          canvas.drawLine(635,126,645,126, paint);
          
          canvas.drawLine(635,154,645,154, paint);//3  ตั้ง
          canvas.drawLine(635,168,645,168, paint);
          canvas.drawLine(635,182,645,182, paint);
          canvas.drawLine(635,196,645,196, paint);
          
          canvas.drawLine(635,224,645,224, paint);//4  ตั้ง
          canvas.drawLine(635,238,645,238, paint);
          canvas.drawLine(635,252,645,252, paint);
          canvas.drawLine(635,266,645,266, paint);
          
          canvas.drawLine(635,294,645,294, paint);//5  ตั้ง
          canvas.drawLine(635,308,645,308, paint);
          canvas.drawLine(635,322,645,322, paint);
          canvas.drawLine(635,336,645,336, paint);
          
          canvas.drawLine(635,364,645,364, paint);//6  ตั้ง
          canvas.drawLine(635,378,645,378, paint);
          canvas.drawLine(635,392,645,392, paint);
          canvas.drawLine(635,406,645,406, paint);
          
          canvas.drawLine(635,434,645,434, paint);//7  ตั้ง
          canvas.drawLine(635,448,645,448, paint);
          canvas.drawLine(635,462,645,462, paint);
          canvas.drawLine(635,476,645,476, paint);

          canvas.drawLine(635,504,645,504, paint);//8  ตั้ง
          canvas.drawLine(635,518,645,518, paint);
          canvas.drawLine(635,532,645,532, paint);
          canvas.drawLine(635,546,645,546, paint);

          canvas.drawLine(635,574,645,574, paint);//9  ตั้ง
          canvas.drawLine(635,588,645,588, paint);
          canvas.drawLine(635,602,645,602, paint);
          canvas.drawLine(635,616,645,616, paint);
          
          canvas.drawLine(635,644,645,644, paint);//10  ตั้ง
          canvas.drawLine(635,658,645,658, paint);
          canvas.drawLine(635,672,645,672, paint);
          canvas.drawLine(635,686,645,686, paint);
          
          canvas.drawLine((float) 25.6,345,(float)25.6,355, paint);//1 นอน
          canvas.drawLine((float) 51.2,345,(float)51.2,355, paint);
          canvas.drawLine((float) 76.8,345,(float)76.8,355, paint);
          canvas.drawLine((float) 102.4,345,(float)102.4,355, paint);
          
          canvas.drawLine((float) 153.6,345,(float)153.6,355, paint);//2 นอน
          canvas.drawLine((float) 179.2,345,(float)179.2,355, paint);
          canvas.drawLine((float) 204.8,345,(float)204.8,355, paint);
          canvas.drawLine((float) 230.4,345,(float)230.4,355, paint); 
          
          canvas.drawLine((float) 281.6,345,(float)281.6,355, paint);//3 นอน
          canvas.drawLine((float) 307.2,345,(float)307.2,355, paint);
          canvas.drawLine((float) 332.8,345,(float)332.8,355, paint);
          canvas.drawLine((float) 358.4,345,(float)358.4,355, paint);
          
          canvas.drawLine((float) 409.6,345,(float)409.6,355, paint);//4 นอน
          canvas.drawLine((float) 435.2,345,(float)435.2,355, paint);
          canvas.drawLine((float) 460.8,345,(float)460.8,355, paint);
          canvas.drawLine((float) 486.4,345,(float)486.4,355, paint);
          
          canvas.drawLine((float) 537.6,345,(float)537.6,355, paint);//5 นอน
          canvas.drawLine((float) 563.2,345,(float)563.2,355, paint);
          canvas.drawLine((float) 588.8,345,(float)588.8,355, paint);
          canvas.drawLine((float) 614.4,345,(float)614.4,355, paint);
          
          canvas.drawLine((float) 665.6,345,(float)665.6,355, paint);//6 นอน
          canvas.drawLine((float) 691.2,345,(float)691.2,355, paint);
          canvas.drawLine((float) 716.8,345,(float)716.8,355, paint);
          canvas.drawLine((float) 742.4,345,(float)742.4,355, paint);
          
          canvas.drawLine((float) 793.6,345,(float)793.6,355, paint);//7 นอน
          canvas.drawLine((float) 819.2,345,(float)819.2,355, paint);
          canvas.drawLine((float) 844.8,345,(float)844.8,355, paint);
          canvas.drawLine((float) 870.4,345,(float)870.4,355, paint);
          
          canvas.drawLine((float) 921.6,345,(float)921.6,355, paint);//8 นอน
          canvas.drawLine((float) 947.2,345,(float)947.2,355, paint);
          canvas.drawLine((float) 972.8,345,(float)972.8,355, paint);
          canvas.drawLine((float) 998.4,345,(float)998.4,355, paint);
          
          canvas.drawLine((float) 1049.6,345,(float)1049.6,355, paint);//9 นอน
          canvas.drawLine((float) 1075.2,345,(float)1075.2,355, paint);
          canvas.drawLine((float) 1100.8,345,(float)1100.8,355, paint);
          canvas.drawLine((float) 1126.4,345,(float)1126.4,355, paint);
          
          canvas.drawLine((float) 1177.6,345,(float)1177.6,355, paint);//10 นอน
          canvas.drawLine((float) 1203.2,345,(float)1203.2,355, paint);
          canvas.drawLine((float) 1228.8,345,(float)1228.8,355, paint);
          canvas.drawLine((float) 1254.4,345,(float)1254.4,355, paint);
       }
  }
}


main.xml
Code: Select all
<?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" >
</LinearLayout>


Thank
l3_o_O_lvl
Freshman
Freshman
 
Posts: 2
Joined: Tue Jan 24, 2012 7:04 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests