Drawing on a custome made view H.E.L.P.

Problems with Canvas, OpenGL, etc...

Drawing on a custome made view H.E.L.P.

Postby VeeTee » Sat Mar 12, 2011 5:19 pm

Hi guys,
I need your experience.
Problem : I need to be able to draw thing (rect, circ,etc) on one part of a FlipperView....
My main.xml has a main linearLayout. In this LinearLayout I have a ViewFlipper with 2 linearlayouts in it. The first linearlayout has soms buttons, inputfiels,etc... the second one should have a special view in wich I can draw the things I choose in the first part.
So I have created a new view wich extends the View class so I can play with the ondraw methode. But I can not get it to work.
This is what I have so far...


Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent" android:id="@+id/layout_main" xmlns:android="http://schemas.android.com/apk/res/android">
<ViewFlipper android:id="@+id/details" android:layout_width="fill_parent"        android:layout_height="fill_parent">
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="match_parent">

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="match_parent">
//an instance of my new ViewClass
   android:id="@+id/draw" android:layout_width="match_parent"


Code: Select all
public class ViewClass extends View {
   Paint paint = new Paint();
  public DrawView(Context context) {

    public void onDraw(Canvas canvas) {
   //depending on some params....
   draw this, draw that...

and then my main activity

Code: Select all
public class SmsDraw extends Activity implements OnTouchListener{
ViewClass vClass;

public void onCreate(Bundle savedInstanceState) {

  vClass = (ViewClass) findViewById(R.id.draw);
// with somewhere a draw function excecuted by a button
private void start() {
      //where can I get a canvas ? Canvas c = new Canvas();

So I need to be able to draw on the thing VIEWCLASS with id = draw in my main.xml...
How can I do this ? please help me with an explanation and solution and not just a solution :-)

Thanks VeeTee
Posts: 2
Joined: Sun Feb 27, 2011 12:58 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest