android - Custom onDraw() method not called -
<linearlayout android:id="@+id/svll" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <scrollview android:id="@+id/sv" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"> <!-- <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/scrollbar_2_text" /> --> <com.mypackage.mydrawableview android:layout_width="fill_parent" android:layout_height="wrap_content" /> </scrollview> </linearlayout>
public class mydrawableview extends view { context thiscontext; public mydrawableview(context context, attributeset attr) { super(context); thiscontext = context; } @override protected void ondraw(canvas canvas) { super.ondraw(canvas); final paint paint = new paint(); paint.setcolor(color.blue); paint.settextsize(12); canvas.drawtext("blah blah", 0, 100, paint); } }
public class myactivity extends activity { // member variable declaration here // called when activity first created. @override public void oncreate(bundle savedinstancestate) { // code here super.oncreate(savedinstancestate); setcontentview(r.layout.xmllayout); linearlayout svll = (linearlayout) findviewbyid(r.id.svll); svll.setlayoutparams(new linearlayout.layoutparams(300, 300)); } }
i putting breakpoint, breakpoint never hit inside ondraw()
method, what's wrong ?
add setwillnotdraw(false)
in mydrawableview constructor. original answer here.
Comments
Post a Comment