2017-03-14 8 views
0

ImageViewとその中のTextViewを持つフレームレイアウトがあります。私は絵の中心にそのテキストを作るつもりです。 問題はイメージが収まりません。イメージビューはコンテンツの高さをラップしません。。絵を見てください: enter image description hereAndroid:フレームレイアウト - ImageViewの高さが合わない

私はそれがこのように見える必要があります。 enter image description here

私は高さを混合し、(ラップ内容とマッチ親)を試みたが、画像はまだよく適合しません。 これは、XMLである:

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      card_view:srcCompat="@drawable/tvrdjava" 
      android:id="@+id/imageView3" /> 

     <TextView 
      android:text="TextView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/textView6" 
      android:textAlignment="center" 
      android:textColor="@android:color/white" 
      /> 

</FrameLayout> 

画像は、異なる解像度ごとに異なる描画可能なフォルダ(hdpi、MDPI、xhdpi、xxhdpi、xxxhdpi)です。

+0

なぜImageViewとTextViewにRelativeLayoutを使用しないのですか? – MatPag

+0

Uはandroid:background = "@ drawable/your_image .. –

+0

を使用することができます。テキストに画像を置くことができないので@MatPag – IkePr

答えて

1

あなたはアイデアのために@MatPagに代わり

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     app:srcCompat="@drawable/ok"/> 

    <TextView 
     android:id="@+id/editText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:textSize="30sp" 
     android:text="TextView"/> 

</RelativeLayout> 
+0

このフレームレイアウトはLinearLayout(垂直)にあり、何らかの理由で動作しました。 – Ivan

0

感謝をRelativeLayoutを使用して、このような何かを試してみてください。このフレームレイアウトをLinearLayout(垂直)に配置すると効果があります。

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:srcCompat="@drawable/tvrdjava" 
      android:id="@+id/imageView8" 
      android:adjustViewBounds="true" 
      android:cropToPadding="false" /> 

     <TextView 
      android:text="TrTemp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/textView3" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textAlignment="center" 
      android:gravity="center" 
      /> 

    </FrameLayout> 
0

これは私の仕事です。

   <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/homepage_background_imageView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1" 
        android:adjustViewBounds="true" 
        android:src="@drawable/background_homepage"/> 

      </FrameLayout> 
関連する問題