[android-developers] Re: How to draw text in rectangle

2009-08-05 Thread Yusuf T. Mobile

Kent is right, the easy way is with TextView, but if you want the
flexibility of placing your text and rectangle anywhere (like with a
bouncing text+rectangle on the screen), then the Canvas class has
drawText() and drawRect().



Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.




On Aug 4, 11:41 pm, Kent  wrote:
> I don't know what you are trying to do, but if it's just simple layout
> stuff you may be making life more difficult for yourself than
> necessary. Try one of these things instead:
>
> a: use a textView and set it's background property (either to a color
> #argb or to a drawable). This has limitations, but for a single text
> item it should work fine.  Depending on what you want, you can tweak
> the layout_width/layout_height parameters to get pretty close. An .xml
> example:
>
>      android:id = "@+id/text1"
>     android:background = "@+drawable/filename"
>     android:layout_width="wrap_content"
>     android:layout_height="wrap_content"
>     android:text="@string/hello"
>     android:textSize = "12pt"
>     android:textStyle= "bold"
>     android:textColor= "#001"
> />
>
> b: use a layout(relativeLayout, etc) and set it's background/size then
> put the textView or anything else you want into it. You could also
> leave the background blank and put the drawable into the layout
> directly.
>
> http://schemas.android.com/apk/res/
> android"
>     android:id = "@+id/container1"
>     android:background = "@+drawable/image"
>     android:layout_width="wrap_content"
>     android:layout_height="wrap_content"
>     android:layout_marginTop="20dip"
>     android:layout_marginLeft="20dip"
>     >
>              android:id = "@+id/text1"
>         android:text="@string/hello"
>         android:layout_width="wrap_content"
>         android:layout_height="wrap_content"
>         android:layout_centerHorizontal="true"
>         android:layout_centerVertical="true"
>     />
> 
>
> There is an awful lot of flexibility, so without knowing what you are
> after ... it's hard to say. Probably check the beginners forum 
> at:http://groups.google.com/group/android-beginnersand there will be a
> lot more information on this sort of thing.
>
> Hope that helps.
>
> On Aug 4, 6:54 am, wr1472  wrote:
>
>
>
> > Hi,
>
> > I have just started looking at developing for Google Android and want
> > to draw a rectangle with some text in it that I then want to position
> > where i want on screen.
>
> > I have got as far as drawing a rectangle on screen using a
> > ShapeDrawable and RectShape I now want to put some text in the
> > rectangle. How can I best do this? Should I be looking at somehow
> > adding a textView to the RectShape? Or am i going down the the wrong
> > avenue completely?
>
> > Some pointers would help greatly!
>
> > Thanks
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: How to draw text in rectangle

2009-08-04 Thread Kent

I don't know what you are trying to do, but if it's just simple layout
stuff you may be making life more difficult for yourself than
necessary. Try one of these things instead:

a: use a textView and set it's background property (either to a color
#argb or to a drawable). This has limitations, but for a single text
item it should work fine.  Depending on what you want, you can tweak
the layout_width/layout_height parameters to get pretty close. An .xml
example:



b: use a layout(relativeLayout, etc) and set it's background/size then
put the textView or anything else you want into it. You could also
leave the background blank and put the drawable into the layout
directly.

http://schemas.android.com/apk/res/
android"
android:id = "@+id/container1"
android:background = "@+drawable/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="20dip"
>



There is an awful lot of flexibility, so without knowing what you are
after ... it's hard to say. Probably check the beginners forum at:
http://groups.google.com/group/android-beginners and there will be a
lot more information on this sort of thing.

Hope that helps.


On Aug 4, 6:54 am, wr1472  wrote:
> Hi,
>
> I have just started looking at developing for Google Android and want
> to draw a rectangle with some text in it that I then want to position
> where i want on screen.
>
> I have got as far as drawing a rectangle on screen using a
> ShapeDrawable and RectShape I now want to put some text in the
> rectangle. How can I best do this? Should I be looking at somehow
> adding a textView to the RectShape? Or am i going down the the wrong
> avenue completely?
>
> Some pointers would help greatly!
>
> Thanks
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---