set paint style canvas.drawLine(100, 100, 200, 200, new Paint()); instead of new paint define pay style
On Mar 22, 11:27 am, "Vishwesh R." <vish...@gmail.com> wrote: > my code:- > > main.xml > > <?xml version="1.0" encoding="utf-8"?> > > <com.MyPack.canvasexample.Myview > android:id="@+id/view1" > android:layout_width="fill_parent" > xmlns:android="http://schemas.android.com/apk/res/android" > android:layout_height="fill_parent" > android:clickable="true" > /> > > Myview.java > > package com.MyPack.canvasexample; > > import android.content.Context; > import android.graphics.Canvas; > import android.graphics.Paint; > import android.util.AttributeSet; > import android.view.View; > > public class Myview extends View { > > public Myview(Context context) { > super(context); > // TODO Auto-generated constructor stub > this.invalidate(); > } > > public Myview(Context context, AttributeSet attrs, int defStyle) { > super(context, attrs, defStyle); > // TODO Auto-generated constructor stub > this.invalidate(); > } > > public Myview(Context context, AttributeSet attrs) { > super(context, attrs); > // TODO Auto-generated constructor stub > this.invalidate(); > } > > @Override > protected void onDraw(Canvas canvas) { > // TODO Auto-generated method stub > super.onDraw(canvas); > > canvas.drawLine(100, 100, 200, 200, new Paint()); > } > > @Override > protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) > { > // TODO Auto-generated method stub > super.onMeasure(widthMeasureSpec, heightMeasureSpec); > > } > > } > > canvasexample.java > > package com.MyPack.canvasexample; > > import android.app.Activity; > import android.os.Bundle; > > public class canvasexample extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > View v= findViewById(R.id.view1); > if(v==null) > Log.w("isnull", "null"); > else > Log.w("isnull", "not null"); > > } > > } > > this is my code.... > the log displays "not null" for "isnull" tag that is view to b not > null... > do we need to write anything in manifest file. > in graphical view of main.xml i can see a line drawn on the canvas but > when i execute my program it shows nothing on canvas... > ya we knw that we can draw a line without creating an extra view but > we r trying to do it by creating a custom view... > > On Mar 18, 9:55 pm, Aisthesis <marsh...@marshallfarrier.com> wrote:> did you > use the fully qualified name when you put it in main.xml? > > e.g.: com.google.myapp.MyView > > if that doesn't do it, it's hard to debug without any code--also there > > are ways to draw a line without creating an extra custom view > > > On Mar 17, 8:05 am, "Vishwesh R." <vish...@gmail.com> wrote: > > > > hi, > > > im a beginner > > > i have created a Myview wich extends View class. i have drawn a > > > line on this view (that is Myview) in its onDraw() method. > > > i included my view in its main.xml > > > > it shows no error but when i run this application, it loads the canvas > > > but im unable to see the line wich i have drawn in Myview > > > the coordinate of the line do lie on canvas but it not visible after > > > the application is run.. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en