3

テキストボックス(複数行、ほぼ5行)と画像ビューを持つ線形レイアウトがあります。テキストビュー(オーバーラップ)に画像を描画することはできますか?

注: 画像の座標を指定する必要があります。これは静的ではなく、テキストの上のどこにでもある可能性があります。

このモックアップのようなもの:

ここに画像の説明を入力

4

4 に答える 4

1

RelativeLayout を使用して実現できると思います。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
                android:id="@+id/Textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:text="@string/Text2display"
                android:textColor="#EEDCAA" />


        <ImageView
            android:id="@+id/choose_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-46dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/description_logo"
            android:src="@drawable/user2" />

    </RelativeLayout>

TextView ブロックを ImageView の上に配置することで、画像ビューが TextView にオーバーラップするようになります。ここで、要件と位置に基づいて、リンクから次のコマンドを使用します。

http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

上下左右揃えることができます。負の値を使用して ImageView をナビゲートします。下の位置合わせなどを使用している場合は、オーバーラップします。これが役に立ったかどうか教えてください

Linear Layout の特定の理由はありますか?

于 2012-09-02T00:27:34.543 に答える
0

本当に (本当に) LinearLayout を使用する必要がある場合は、TextView をサブクラス化し、onDrawをオーバーライドして画像を描画できます。

于 2012-09-02T01:20:36.843 に答える
0

RelativeLayout を使用すると、これを簡単に行うことができます。LinearLayout を使用する特定の理由がない限り、 ImageView を TextView と重ねることができます。

于 2012-08-25T14:21:28.113 に答える