2013-07-13 7 views
5

Ich habe eine RelativeLayout mit einer ImageView auf der linken Seite und dann eine TextView auf der rechten Seite. Die TextView wird von einer Website über ihre API heruntergeladen, so dass der Inhalt jedes Mal anders ist.Positionieren einer Ansicht unter zwei Ansichten (oder der niedrigsten Ansicht)

Ich möchte eine weitere TextView unter diesen beiden haben, aber ich habe ein Problem, wenn die TextView Länge ist weniger als die ImageView. Wenn dies passiert, überlappen TextView am unteren Rand die ImageView, weil ich die untere TextView auf der unteren rechten Seite unter der TextView ausrichten.

Was ich passieren muss, ist in der Lage, die untere TextView unter welcher Ansicht ist die niedrigste Ausrichtung.

Das ist mein Layout XML:

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

    <ImageView 
     android:id="@+id/itemImageView" 
     android:layout_width="100dp" 
     android:layout_height="80dp" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:src="@drawable/id_image" /> 

    <TextView 
     android:id="@+id/itemContentsTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/itemImageView" 
     android:layout_marginRight="2dp" 
     android:layout_marginTop="2dp" 
     android:text="Sample contents\nSample contents\nSample contents" /> 

    <TextView 
     android:id="@+id/itemIdTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/itemContentsTextView" 
     android:layout_marginBottom="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" 
     android:text="1234" /> 

</RelativeLayout> 

Antwort

4

Sie sollten LinearLayout als Top-Mutter erstellen und orientation:vertical machen. Dann fügen Sie zuerst Ihre relativeLayout hinzu und fügen Sie dann Ihre TextView hinzu.

So wird es so aussehen.

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

     <ImageView 
       android:id="@+id/itemImageView" 
       android:layout_width="100dp" 
       android:layout_height="80dp" 
       android:layout_alignParentLeft="true" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="5dp" 
       android:src="@drawable/id_image" /> 

     <TextView 
       android:id="@+id/itemContentsTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignRight="@+id/itemImageView" 
       android:layout_marginRight="2dp" 
       android:layout_marginTop="2dp" 
       android:text="Sample contents\nSample contents\nSample contents" /> 
    </RelativeLayout> 
    <TextView 
      android:id="@+id/itemIdTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="5dp" 
      android:text="1234" /> 
</LinearLayout> 
3

Wickeln Sie das obere ImageView und TextView in einem anderen RelativeLayout und verwenden, die als Anker für Ihren Boden TextView.

Etwas Ähnliches (nicht getestet):

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

    <RelativeLayout 
     android:id="@+id/wrappingLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/itemImageView" 
      android:layout_width="100dp" 
      android:layout_height="80dp" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="5dp" 
      android:src="@drawable/id_image" /> 

     <TextView 
      android:id="@+id/itemContentsTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/itemImageView" 
      android:layout_marginRight="2dp" 
      android:layout_marginTop="2dp" 
      android:text="Sample contents\nSample contents\nSample contents" /> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/itemIdTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/wrappingLayout" 
     android:layout_marginBottom="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="5dp" 
     android:text="1234" /> 

</RelativeLayout> 
1

Verwenden Sie eine weitere RelativeLayout ich habe Getestet und Text überlappt nie

so soll es sein:

<RelativeLayout 
    android:id="@+id/temp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/itemImageView" 
     android:layout_width="100dp" 
     android:layout_height="80dp" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/itemContentsTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/itemImageView" 
     android:layout_marginRight="2dp" 
     android:layout_marginTop="2dp" 
     android:text="Sample contents\nSample contents\nSample contents" /> 
</RelativeLayout> 

<TextView 
    android:id="@+id/itemIdTextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/temp" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="5dp" 
    android:text="1234" /> 

Verwandte Themen