You need to override the ImageView constructor with attributeSet. Define public CustomDrawableView (Context context, AttributeSet attrs) as well.. Your layout file looks for this constructor.
Neeraj On Jul 16, 7:55 am, Jags <[email protected]> wrote: > my custom view looks as below > _______________________________________________ > > package com.mypackage; > > import java.util.ArrayList; > import java.util.List; > > import android.content.Context; > import android.graphics.Canvas; > import android.graphics.Color; > import android.graphics.drawable.ShapeDrawable; > import android.graphics.drawable.shapes.RectShape; > import android.widget.ImageView; > > public class CustomDrawableView extends ImageView { > // private ShapeDrawable mDrawable; > public int imageid = 0; > ShapeDrawable bgDrawable = null; > List<ShapeDrawable> ls = new ArrayList<ShapeDrawable>(); > final int COUNT_SUMMERY = 3; > final int VERTICAL_OFFSET = 200; > final int HORIZENTAL_OFFSET = 20; > final int HORIZENTAL_GAP = 85; > final int VERTICAL_Y_POINT = 15; > final int VERTICAL_MAX_HEIGHT = 195; > final int HORIZENTAL_WIDTH = 60; > final int percentage[] = {25, 40, 35}; > public CustomDrawableView(Context context, int id) { > super(context); > > imageid = id; > > switch(id) { > case R.drawable.summarychart: > for(int i = 0; i < COUNT_SUMMERY; i++) { > int x = HORIZENTAL_OFFSET + (HORIZENTAL_GAP * > i); > int width = HORIZENTAL_WIDTH; > int height = VERTICAL_MAX_HEIGHT * > percentage[i] / 100; > int y = VERTICAL_OFFSET + VERTICAL_Y_POINT + > VERTICAL_MAX_HEIGHT - > height; > > ShapeDrawable objDrawable = new > ShapeDrawable(new RectShape()); > int color = 0; > switch(i) { > case 0: > color = Color.RED; > break; > case 1: > color = Color.GREEN; > break; > case 2: > color = Color.YELLOW; > break; > } > objDrawable.getPaint().setColor(color); > objDrawable.setBounds(x, y, x + width, y + > height); > ls.add(objDrawable); > } > break; > default: > break; > } > > int x = 0; > int y = 0; > int width = 320; > int height = 480; > bgDrawable = new ShapeDrawable(new RectShape()); > bgDrawable.getPaint().setColor(0xffffffff); > bgDrawable.setBounds(x, y, x + width, y + height); > } > > protected void onDraw(Canvas canvas) { > /* // Draw the white background > // bgDrawable.draw(canvas); > // Draw the bitmaps > Bitmap bmp = BitmapFactory.decodeResource(getResources(), > imageid); > canvas.drawBitmap(bmp, 0, VERTICAL_OFFSET, null); > */ // Draw bars > super.onDraw(canvas); > > for(int i = 0; i < COUNT_SUMMERY; i++) { > ShapeDrawable objDrawable = ls.get(i); > objDrawable.draw(canvas); > } > } > > } > > ____________________________________________________________ > > now i do in layout > > <com.mypackage.CustomDrawableView > android:layout_width="wrap_content" > android:layout_height="wrap_content" > android:src="@drawable/mychart" /> > > but in layout i see a message > NoSuchMethodException:com.mypackage.CustomDrawableView.<init>(Android.conte > xt.Context, > Android.util.AttributeSet) > > and while i run it crashes. if i uncomment the drawable way, then it > works, but other layouts are not displayed. > > any help is appreciated > > thanksin advance > jags > > _______________________________________________________________ > On Jul 13, 9:45 pm, Matty <[email protected]> wrote: > > > > > If you want to draw on top of an ImageView, I would extend it and > > override it's onDraw method. This provides you a [relative] canvas to > > draw on. Just be sure to call super.onDraw() if you want the image to > > show up also. > > > On Jul 13, 11:23 am,Jags<[email protected]> wrote: > > > > I am trying to put a background image and draw on top of that screen. > > > I assumed activity will have a on draw method, but it does not have. > > > it seems i need to use surfaceview. Can I put a surfaceview on top of > > > the image view and make it transparent ? any example/tutorial i can > > > refer to ?- Hide quoted text - > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

