2017-05-02 2 views
2

今私は、(テキストが画面の下部にある)このような出力を取得していますImageViewの下部に画像を設定するが、イメージソースではない画像サイズで

enter image description here

しかし、私は出力をしたい方法次の画像のように。

enter image description here

これは私のXMLコードです:

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/rlBottom" 
      > 

      <ImageView 
       android:id="@+id/coringImage" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:src="@drawable/img_electricity" 
       /> 

      <TextView 
       android:id="@+id/fdc_tvUnGeneration" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="@dimen/default_margin" 
       android:layout_marginRight="@dimen/default_margin" 
       android:textColor="@color/color_white" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:layout_below="@+id/fdc_tvAVGeneration" 
       android:layout_alignParentBottom="true" 
       /> 
     </RelativeLayout> 
+0

セットfdc_tvUnGenerationにマージン底を異なるスクリーンその画像内の異なるサイズを有するのでfdc_tvUnGenerationに –

+0

セットマージン底部が動作していない要件ごとに。 –

答えて

1

は、このコードを試してみてください...

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/rlBottom"> 

    <ImageView 
     android:id="@+id/coringImage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/img_electricity"/> 

    <TextView 
     android:id="@+id/fdc_tvUnGeneration" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/default_margin" 
     android:layout_marginRight="@dimen/default_margin" 
     android:layout_marginBottom="5dp" 
     android:textColor="@color/color_white" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_below="@+id/fdc_tvAVGeneration" 
     android:layout_gravity="bottom|center"/> 
</FrameLayout> 
0

あなたは

0

はこれを試してみてください、あなたのImageViewの中 android:scaleType="fitXY" を使用することができます

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
tools:context="com.us.upen.mymusicplayer.ui.SplashActivity"> 

<ImageView 
    android:id="@+id/coringImage" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/img_electricity" /> 

<TextView 
    android:id="@+id/fdc_tvUnGeneration" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/coringImage" 
    android:layout_alignParentStart="true" 
    android:gravity="center" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 
</RelativeLayout> 

私はTextViewに属性android:layout_alignBottom="@+id/coringImage"android:layout_marginBottom="10dp"を追加TextView

2.からこの

0

1.削除属性android:layout_belowandroid:layout_alignParentBottom="true"をチェックします。

FYI、ここでは、10dpとしてボトムマージンを使用しています。必要に応じて変更することができます。ここで

は一例です:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/rlBottom"> 

    <ImageView 
     android:id="@+id/coringImage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@mipmap/ic_launcher" /> 

    <TextView 
     android:id="@+id/fdc_tvUnGeneration" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/default_margin" 
     android:layout_marginRight="@dimen/default_margin" 
     android:layout_marginBottom="10dp" 
     android:textColor="@color/color_white" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:layout_alignBottom="@+id/coringImage" 
     android:layout_centerHorizontal="true" 
     android:text="I am a Text"/> 
</RelativeLayout> 

OUTPUT:

enter image description here

希望、これはあなたがアンドロイド削除する必要が〜

0

を助ける:layout_alignParentBottom = "真の"from textview

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

<ImageView 
    android:id="@+id/coringImage" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/wood01_c_pia" /> 

<TextView 
    android:id="@+id/fdc_tvUnGeneration" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/coringImage" 
    android:gravity="center" 
    android:text="test" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 
</RelativeLayout> 
関連する問題