2015-06-26 3 views
0

У меня есть следующий макет:Align TextView в нижнюю часть ImageView внутри RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 
     android:src="@drawable/miclubpyme_backgroundl" /> 

    <TextView 
     android:id="@+id/txtStoreName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="I am a text" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

</RelativeLayout> 

Я хотел бы иметь TextView выравнивать к нижней части ImageView, но не за его пределами. Добавление layout_alignParentBottom заставляет RelativeView занимать всю высоту экрана.

Вот изображение exemplyfing это:

enter image description here ``

Любая помощь будет принята с благодарностью. Спасибо!

+0

Какая часть изображения, а какая нет? Похоже, есть еще одна часть, которая занимает пространство между изображением и нижней частью макета устройства. – Eenvincible

ответ

3

Вы бы гнездиться свой ImageView и ваш TextView внутри ViewGroup, который имеет такую ​​же высоту, как и ваш ImageView.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

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

     <ImageView 
      android:id="@+id/img" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:scaleType="centerCrop" 
      android:src="@drawable/miclubpyme_backgroundl" /> 

     <TextView 
      android:id="@+id/txtStoreName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:text="I am a text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </FrameLayout> 

</RelativeLayout> 
0

Вы ищете android:align_bottom="@+id/img" на вашем TextView, а не android:align_parentBottom="true".

+0

Нет, я пробовал это, и это не сработало для меня. Спасибо, хотя. –

+0

Странно, потому что я просто собрал быстрый макет, и он отлично работает ... – themarshal

0

Попробуйте ниже в вашем TextView android:layout_alignBottom = «@ ид/IMG» `

+0

Нет, я пробовал это, и это не сработало для меня. Спасибо, хотя. –

Смежные вопросы