25

画面の上部にアプリケーションバーを配置すると、次の図のようになります。

ここに画像の説明を入力してください

次に、画像の上にテキストを設定して、画像が次のようになるようにします。

ここに画像の説明を入力してください

画像の上にテキストを設定するにはどうすればよいですか?前もって感謝します

4

8 に答える 8

31

テキストを画像の中央に配置するだけの場合、必要なのはTextViewだけで、画像ビューはありません。android:background="@drawable/yourImage"TextViewに設定します。

于 2011-04-25T11:28:36.727 に答える
25

以下のコードをお試しください。

<?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>
于 2011-04-25T11:19:10.020 に答える
22

それが私がそれをした方法であり、あなたが要求したとおりに機能しました:

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

これには相対レイアウトを使用します

于 2013-01-15T12:02:33.520 に答える
8
  1. 使用FrameLayout (チュートリアル)
<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"

于 2011-04-25T11:35:54.957 に答える
2

画像の上にテキストを表示する方法はたくさんあります

1)テキストでこの画像を作成できます。2)テキストビューの背景(この画像)を設定できます。

于 2011-04-25T11:20:50.197 に答える
2

相対レイアウト上の他のビューの上に任意のビューを配置する場合は、低レベルのビューの下に最上位のビューを定義する必要があります...たとえば

<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" />
于 2014-12-23T06:38:29.130 に答える
1

私が正しく推測した場合、あなたはあなたのサンプルのためにヘッダーを使おうとしています。

その画像として背景を設定し、このようにテキストビューを追加します。

<?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を使用してレイアウトをマージする必要があります。

フレームレイアウトについては、このサンプルを確認してください

于 2011-04-25T11:22:48.033 に答える
0

次のように、FrameLayoutを使用してImage上にテキストを表示できます。-

<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>
于 2017-01-15T14:44:00.680 に答える