Why do you override onMeasure and onPaint? It's easier to set
properties of your view in the xml file.
And content should be wrapped, not warped :-)
On Nov 8, 6:35 pm, zigang <[EMAIL PROTECTED]> wrote:
> Hi,i am a newer of android world. I hava a question like this:
> I write my custom view as MyView extends View,but it doesn't visible
> in screen,is there someone meets the same question?
> code like this:
> public class MyView extends View {
> public MyView(Context c){
> super(c);
> }
> public MyView(Context c,AttributeSet attr){
> super(c,attr);
> }
>
> @Override
> protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
> {
> setMeasuredDimension(160, 160);
> }
> @Override
> protected void onDraw(Canvas canvas) {
> super.onDraw(canvas);
> Paint paint=new Paint();
> paint.setTextSize(30);
> paint.setColor(0xffffff);
> canvas.drawText("This is a test word", 1,20, paint);
> }
>
> }
>
> xml file like this:
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:orientation="vertical"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent"
> >
> <com.test.MyView
> android:id="@+id/hi"
> android:layout_width="fill_parent"
> android:layout_height="warp_content"
> />
> </LinearLayout>
>
> Thanks for you help!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---