Подтвердить что ты не робот

Как установить текст над imageView?

Я помещаю панель приложений в верхней части экрана, и она выглядит следующим образом:

enter image description here

Теперь я хочу установить текст над изображением, чтобы изображение выглядело следующим образом:

enter image description here

Как установить текст поверх изображения? Спасибо заранее

4b9b3361

Ответ 1

Пожалуйста, попробуйте приведенный ниже код.

<?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>

Ответ 2

Если вам просто нужен текст, ориентированный по изображению, все, что вам нужно, это TextView, без изображения. Установите android:background="@drawable/yourImage" в TextView.

Ответ 3

Вот как я это сделал, и он работал точно так же, как вы просили:

<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" />

Используйте Относительный макет для этого

Ответ 4

 
<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>

или

2.Используйте изображение в качестве фона: android:background="@drawable/yourImage"

Ответ 5

существует много способов отображения текста над изображением

1) u может сделать это изображение с текстом.. 2) u может установить фон (это изображение) для текстового просмотра.

Ответ 6

Если я правильно догадался, вы пытаетесь использовать образец заголовка для вас.

Установите фоновое изображение в качестве этого изображения и добавьте текстовое представление в это.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="55px"
    android:background="@drawable/testheader"
    android:layout_width="fill_parent"
    android:orientation="horizontal">           
        <TextView android:id="@+id/quaddeal_header_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dip"
            android:text="Campus"
            android:textSize="20sp"
            android:textColor="@color/white"
            android:layout_marginLeft="90dip"/>
</RelativeLayout>

Или вам нужно объединить макеты с помощью Framelayout.

Отметьте Пример для компоновки фреймов

Ответ 7

Если вы хотите поместить любое представление на любой другой вид в Relative layout, вам нужно определить представление верхнего уровня ниже представления низкого уровня... например

<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_margin="1dp"
    android:gravity="center"
    android:text="Hello"
    android:textColor="#000000" />

Ответ 8

Вы можете использовать FrameLayout для получения текста над изображением, как показано ниже: -

<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>