2016-04-11 1 views
0

J'ai essayé presque tout de Gravity à alignParentTop et layout_above mais rien ne semble fonctionner ici.Comment mettre texte vue au-dessus de l'image et au bas de la mise en page

J'ai un ImageView et un TextView J'utilise ViewPager pour afficher des images différentes et leur text respective.

Le problème est que, il affiche Text en haut et l'image après.

Je veux qu'il affiche Image et en dessous affiche TextView.

C'est ce que je reçois après avoir ajouté suivant 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

me guider Veuillez comment mettre Text après la Image

Répondre

1

En utilisant l'attribut android:layout_below devrait résoudre votre problème:

<?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 à son meilleur !! Merci beaucoup :) – user2052394

1

Ajouter android:layout_below="@+id/image_view" dans votre TextView

1

Essayez ceci:

<?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> 

espérons qu'il vous aidera !!

+0

C'est ce que je reçois après l'application de ce code http://imgur.com/PGFabq6 – user2052394

1

Essayez ceci peut vous aider à

<?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

Vous pouvez définir cette structure façon de remorquage, première définition android propriété Textview: layout_below comme id ImageView comme ci-dessous

<?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> 

Et autre utilisation LineLinearLayout et définissez l'orientation verticale comme suit

<?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>