how to set a text over an imageView?

2019-01-13 21:14发布

I am placing an application bar on the top of the screen and it looks as the following figure:

enter image description here

Now i want to set a text over the image, so that the image looks as follows:

enter image description here

How to set a text over an image? Thanks in advance

8条回答
够拽才男人
2楼-- · 2019-01-13 21:49

If you simply want text centered over an image, all you need is a TextView, no image view. Set android:background="@drawable/yourImage" on the TextView.

查看更多
叼着烟拽天下
3楼-- · 2019-01-13 21:52
  1. Use FrameLayout (Tutorial)
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/ImageView01"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:src="@drawable/lake"
        android:scaleType="matrix"></ImageView>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:textSize="40dp"
        android:text="@string/top_text" />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/bottom_text"
        android:layout_gravity="bottom"
        android:gravity="right"
        android:textColor="#fff"
        android:textSize="50dp" />
</FrameLayout>

Or

2.Use an image as a background: android:background="@drawable/yourImage"

查看更多
4楼-- · 2019-01-13 21:55

You can use FrameLayout to achieve text over Image as below:-

<FrameLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageButton
        android:id="@+id/imgbtnUploadPendingPods"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/com" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_gravity="center"
        android:text="hii"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</FrameLayout>
查看更多
该账号已被封号
5楼-- · 2019-01-13 21:56

there many way to display text over an image

1) u can make this image with text.. 2) u can set background(this image) for textview.

查看更多
【Aperson】
6楼-- · 2019-01-13 21:58

Please try the below Code.

<?xml version="1.0" encoding="utf-8"?>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:background="@drawable/your background image">


            <LinearLayout 
                android:layout_height="fill_parent"
                android:layout_width="fill_parent" 
                android:layout_weight="1"
                android:gravity="center" 
                android:orientation="vertical">

                <TextView 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:textColor="@color/white"
                    android:textSize="18sp" 
                    android:textStyle="bold"
                    android:singleLine="true" 
                    android:text="Subject"/>

            </LinearLayout>

</LinearLayout>
查看更多
地球回转人心会变
7楼-- · 2019-01-13 22:05

That's how I did it and it worked exactly as you asked for:

<ImageView
    android:id="@+id/myImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/myImageSouce" />

<TextView
    android:id="@+id/myImageViewText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/myImageView"
    android:layout_alignTop="@+id/myImageView"
    android:layout_alignRight="@+id/myImageView"
    android:layout_alignBottom="@+id/myImageView"
    android:layout_margin="1dp"
    android:gravity="center"
    android:text="Hello"
    android:textColor="#000000" />

Use Relative layout for this

查看更多
登录 后发表回答