ANDROID — How to display text on an image?

不羁的心 提交于 2019-12-09 01:05:24

问题


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.


回答1:


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>



回答2:


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




回答3:


Simply use the android:background attribute of your TextViews.



来源:https://stackoverflow.com/questions/5019517/android-how-to-display-text-on-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!