当前位置: 动力学知识库 > 问答 > 编程问答 >

Android - DrawText on Canvas or TextView.draw

问题描述:

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal" >

<com.gorgo.pirates.MainGamePanel

android:id="@+id/surface"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center" >

</com.gorgo.pirates.MainGamePanel>

<ListView

android:id="@+id/mylist"

android:layout_width="match_parent"

android:layout_height="110dp"

android:layout_gravity="center_horizontal|bottom"

android:background="@android:color/transparent"

android:cacheColorHint="@android:color/transparent"

android:divider="#00000000"

android:drawSelectorOnTop="true" >

</ListView>

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

But I've discovered that I can't create 3 or 4 TextView and setText 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? :(

网友答案:

hints? sure, you have to use this one: http://developer.android.com/reference/android/text/Layout.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: