2016-04-11 7 views
0

Ich habe fast alles von Gravity bis alignParentTop und layout_above versucht, aber nichts scheint hier zu arbeiten.Wie man Text View über das Bild und an der Unterseite des Layouts setzen

Ich habe eine ImageView und TextView ich ViewPager bin mit verschiedenen Bildern anzuzeigen und ihre jeweiligen text.

Das Problem ist, dass seine oben und Bild nach ihm angezeigt wird.

Ich möchte es Image anzeigen und darunter anzeigen TextView.

Dies ist, was ich folgende 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

Bitte leite mich nach dem Hinzufügen bin immer wie Text nach dem Image

Antwort

1

Mit dem android:layout_below Attribut setzen sollte Ihr Problem lösen:

<?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 von seiner besten Seite !! Vielen Dank :) – user2052394

1

hinzufügen android:layout_below="@+id/image_view" in Ihrem TextView

1

Try this:

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

Hoffe, es hilft Ihnen !!

+0

Dies ist, was ich nach der Anwendung dieses Codes http://imgur.com/PGFabq6 bekomme – user2052394

1

dieses Probieren Sie es kann Ihnen helfen,

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

Sie diese Struktur Schlepptau Art und Weise definieren, erste Textview Eigenschaft android definieren: layout_below als Image id wie unten

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

Und andere Verwendung LineLinearLayout und definieren Sie die vertikale Ausrichtung wie folgt

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