ANDROID — How to display text on an image?

2019-02-15 11:17发布

Ok...so here's the scenario.. Starting from scratch, I want to display THREE stars (i have an image that I want to use), centered. I want to post a different word in each star. Of course, I do not want it hard-coded, but once I can get the layout right, the rest will be easy. Can anyone help please? I would be greatly appreciated.

3条回答
\"骚年 ilove
2楼-- · 2019-02-15 11:22

Just use the "background" property that every View has, including TextView, to put the star(s) in. Job done.

查看更多
forever°为你锁心
3楼-- · 2019-02-15 11:34

If you're wanting to just overlay text on top of an image, just wrap the ImageView in a FrameLayout, and then just define a TextView after the ImageView. It will be layered on top. For what you're suggesting in your initial question, Reuben and Yahel's answers will be the better way.

Example:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_image"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Text on Top!"
        />
</FrameLayout>
查看更多
女痞
4楼-- · 2019-02-15 11:48

Simply use the android:background attribute of your TextViews.

查看更多
登录 后发表回答