How to draw text in rectangle

by wr1472 » Tue, 04 Aug 2009 23:15:12 GMT


Sponsored Links
 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

--~--~---------~--~----~------------~-------~--~----~



How to draw text in rectangle

by Kent » Wed, 05 Aug 2009 14:41:45 GMT


 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:

<TextView
    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.

<RelativeLayout xmlns:android=" 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"
    >
    <TextView
        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"
    />
</RelativeLayout>

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:


Sponsored Links


How to draw text in rectangle

by Yusuf T. Mobile » Thu, 06 Aug 2009 01:26:19 GMT


 ent 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:41pm, Kent <andr...@www3d.net> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Android can't read wave files

I am a new Android user, Verizon Droid and I love the product and I
don know how to get an answer so I hope you can help me.  I could
not read wave files emailed to me from my answering service and their
technician said:

<beginning of technicain comments>
Regarding the Verizon Droid user playing "wav" files. I did a little
research and found this to be a problem for many, many, Droid owners.
Our wav files are GSM 6.10 audio format, 13kbps bit rate, mono, 8kHz
sample rate. Droid does not support the GSM 6.10 wav encoding format.
Many voice mail systems, answering services, and MagicJack use this
format. Neither the Droid manufacturer (Motorola) nor Google has a fix
this problem yet.

I did find reference to a $3 program available for the Droid that may
help our customer out though. Since we don't have a Droid to play
with, I can't tell you if it will work or not. The program is called
"Remote Wave".
<end of technicain comments>

SO, I purchased this program at the Android market.  Remote Wave from
Walter Yongtao Wang and I have 24 hours to get a refund.  It did not
work nor could I get my money back.  At this point I am hoping that
remote wave will get updated and work.

As a businessman that is investing in the success of Android, I feel
it is important to point out how the market feels and the above
comments from an IS person needs to be solved.  I am an advocate for
Android and I will help out as needed on this problem.  Thank you for
your support!

KISS2 Principle

-- 

2. Maintaining Aspect Ratio of Background Image

No worries.

16x9 (a la Droid) is probably the most extreme screen aspect ratio
you'll ever encounter in an Android device. Have you considered
creating a scaled and cropped image on the fly the first time the app
is run and caching that on the SD card?

-- 

3. This is Why the Hummingbird Processor in the Samsung Galaxy S is Awesome

4. SOLD!WTS : EVO 4G 2nd *mint*

5. Echo Cancellation

6. mm & Android.mk clean

7. Android copyright act for one of our Applications to be secured