2013-07-13 64 views
5

Tôi có một số RelativeLayout với một số ImageView ở bên trái và sau đó là TextView ở bên phải. Các TextView được tải xuống từ một trang web thông qua API của họ để nội dung của nó sẽ khác nhau mỗi lần.Định vị chế độ xem dưới hai chế độ xem (hoặc chế độ xem thấp nhất)

Tôi muốn có một số khác TextView bên dưới hai nhưng tôi gặp sự cố khi độ dài TextView nhỏ hơn ImageView. Khi điều này xảy ra, số TextView ở dưới cùng sẽ chồng lên ImageView vì tôi căn chỉnh phía dưới TextView để ở bên dưới TextView ở trên cùng bên phải.

Điều tôi cần xảy ra là có thể căn chỉnh phía dưới TextView dưới bất kỳ chế độ xem nào là thấp nhất.

Đây là layout XML của tôi:

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

Trả lời

4

Bạn nên tạo LinearLayout như cha mẹ đầu và làm cho nó orientation:vertical. Sau đó, trước tiên hãy thêm relativeLayout và sau đó thêm TextView của bạn.

Vì vậy, nó sẽ looke như thế này.

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

Bó đầu ImageViewTextView trong RelativeLayout khác và sử dụng như neo cho đáy TextView của bạn.

Something như thế này (không kiểm tra):

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

Sử dụng thêm một RelativeLayout tôi có Tested và văn bản bao giờ trùng lặp

vì thế nên là:

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

Các vấn đề liên quan