DrawText on Canvas or TextView.draw

  • Replies:0
Davide Agu
  • Forum posts: 2

Apr 23, 2013, 10:40:40 AM via Website

In my Android (API 10) game I've used a MVC pattern, a SurfaceView with a canvas and a ListView for input's choice.

1<FrameLayout xmlns:android="http : / / schemas. android. com /apk/res/android"
2 xmlns:tools="http : / / schemas .android .com /tools"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="horizontal" >
6
7 <com.gorgo.pirates.MainGamePanel
8 android:id="@+id/surface"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:layout_gravity="center" >
12 </com.gorgo.pirates.MainGamePanel>
13
14 <ListView
15 android:id="@+id/mylist"
16 android:layout_width="match_parent"
17 android:layout_height="110dp"
18 android:layout_gravity="center_horizontal|bottom"
19 android:background="@android:color/transparent"
20 android:cacheColorHint="@android:color/transparent"
21 android:divider="#00000000"
22 android:drawSelectorOnTop="true" >
23 </ListView>
24
25</FrameLayout>

So now I need to show on screen a lot of String (speeches between characters or narrator text): they stay on screen 4 seconds and they hide themself later, I change the text and reuse them and so on.

I've wrote this Class that worked but it initialized a new TextView every draw() call O_O
h(tt)p://pastebin.com/bYmzpxCg

But I've discovered that I can't create 3 or 4 TextView and set Text whenever I want because of my external Thread that can't modify a View. I've tried with an handler with no success.

So I'm thinking about canvas.drawText() but I don't know if it's the right way.
I need also that my String automatically fits in my widht (Pastebin's class does it) and uses a custom Font.

Hints? :(

Reply