2016-04-11 2 views
0

Я пробовал почти все: от Gravity до alignParentTop и layout_above, но ничего не работает здесь.Как разместить текст над изображением и в нижней части макета

У меня есть ImageView и TextView Я использую ViewPager для отображения различных изображений и их соответствующих text.

Проблема в том, что ее отображение Text сверху и изображение после него.

Я хочу, чтобы он отображал Image и под ним отображал TextView.

Это то, что я получаю после добавления следующих xml

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

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 

     /> 
    <TextView 
     android:id="@+id/image_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:text="Image Text" 
     /> 

</RelativeLayout> 

enter image description here

Просьба направлять меня, как поставить Text после Image

ответ

1

Использование атрибута android:layout_below должно решить вашу проблему:

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

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     /> 

    <TextView 
     android:id="@+id/image_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_below="@+id/image_view" 
     android:text="Image Text" 
     /> 

</RelativeLayout> 
+0

Stackoverflow at the best! Спасибо большое :) – user2052394

1

Добавить android:layout_below="@+id/image_view" в вашем TextView

1

Попробуйте это:

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

    <ImageView 
      android:id="@+id/image_view" 
      android:layout_width="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_height="200dp" 

      /> 
    <TextView 
      android:id="@+id/image_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/image_view" 
      android:paddingBottom="8dp" 
      android:text="Image Text" 
      /> 

</RelativeLayout> 

Надеется, что это помогает !!

+0

Это то, что я получаю после применения этого кода http://imgur.com/PGFabq6 – user2052394

1

Попробуйте это может помочь вам

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="300sp" 
    android:src="@drawable/wallpaper" 
    android:scaleType="centerCrop" 
    android:id="@+id/imageView" /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="This is test" 
    android:textColor="#000" 
    android:textSize="20dp" 
    android:gravity="center" 
    android:layout_alignBottom="@+id/imageView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
</RelativeLayout> 
0

Вы можете определить эту структуру буксировочный образом, первый один определить TextView свойство андроида: layout_below в ImageView ид как сильфона

<?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:orientation="vertical"> 

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 

     /> 

    <TextView 
     android:id="@+id/image_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/image_view" 
     android:layout_gravity="bottom" 
     android:text="Image Text" /> 

</RelativeLayout> 

и другое использование LineLinearLayout и определите ориентацию вертикальной, как показано ниже:

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

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 

     /> 

    <TextView 
     android:id="@+id/image_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Image Text" /> 

</LinearLayout> 
Смежные вопросы