2013-07-13 13 views
5

Mam RelativeLayout z ImageView po lewej stronie, a następnie TextView po prawej stronie. Numer TextView jest pobierany z witryny internetowej za pośrednictwem interfejsu API, dzięki czemu jej zawartość będzie za każdym razem inna.Pozycjonowanie widoku pod dwoma widokami (lub najniższym widokiem)

Chcę mieć kolejny TextView pod tymi dwoma, ale mam problem, gdy długość TextView jest mniejsza niż . Gdy tak się stanie, TextView u dołu będzie nakładać się na ImageView, ponieważ wyrównuję dolną linię TextView, aby znajdowała się poniżej TextView w prawym górnym rogu.

Muszę się zdarzyć, aby wyrównać dno TextView pod dowolnym widokiem, który jest najniższy.

To mój układ 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> 

Odpowiedz

4

Należy utworzyć LinearLayout tematyki rodzica i uczynić go orientation:vertical. Najpierw dodaj swoją relativeLayout, a następnie dodaj swoją TextView.

Tak będzie wyglądać tak.

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

Wrap górna ImageView i TextView w innym RelativeLayout i użyć jej jako kotwica dla dolnej TextView.

Coś takiego (nie testowane):

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

Zastosowanie jeden RelativeLayout mam Przetestowane i tekst nigdy nie zachodzi

tak powinno być:

<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" /> 

Powiązane problemy