-1

私はアンドロイドの学習段階です。ImageViewにTextViewを設定したい。私はポイントを得ていません。感謝します。これが私のXMLコードです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="380dp"       
        android:adjustViewBounds="true"    
        android:scaleType="fitCenter"
        android:background="@drawable/wf" />


    <TextView
   // what should i add here so that it can be visible on image view//
     />

</LinearLayout>
4

4 に答える 4

1

すべてのおかげで、最終的に私は解決策を得ました。私はそれを処理するために FrameLayout を使用しました。

ここにコードがあります

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="380dp"       
        android:adjustViewBounds="true"    
        android:scaleType="fitCenter"
        android:background="@drawable/wf" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8"
        android:textSize="100sp"
        android:layout_marginTop="120dp"
        android:layout_marginLeft="160dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</FrameLayout>
于 2013-11-09T23:52:45.107 に答える
0

あなたが望むのは写真のキャプションのようなものだと思うので、それを実現できる最良の方法は、相対レイアウトを使用することであり、.xml レイアウトは次のようになります。

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="69dp"/>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:text="TextView" />

textView のプロパティに注意してください

android:layout_below="@+id/imageView1"

それが鍵です。何らかの理由でリニアレイアウトをメイン レイアウトとして使用する場合は、メインのリニア レイアウトにネストされているテーブル行 (または別のリニア レイアウト) に相対レイアウトをネストできます。

それが複雑ではないことを願っています

PS:これは初心者向けのアドバイスです

于 2013-11-09T23:52:47.687 に答える
0

RelativeLayoutImageViewとして、最初の子要素として、および2 番目の子要素として使用することもできますTextView

于 2017-09-12T09:12:22.657 に答える