2013-07-13 19 views
5

私はRelativeLayoutにはImageView、次に右側にTextViewと表示されています。 TextViewは、APIを介してウェブサイトからダウンロードされるため、コンテンツは毎回異なるでしょう。2つのビュー(または最下位のビュー)の下にビューを配置

私は別のTextViewをこの2つの下に置いておきたいですが、TextViewの長さがImageViewより小さい場合は問題があります。この場合、下部のTextViewは、TextViewが右上のTextViewの下になるように調整するため、下部のと重複します。

何が起こる必要があるのは、最も低いビューの下で、下部のTextViewを整列できるようにすることです。

これは私のレイアウトXMLである:その一番下のTextViewのアンカーとして

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

答えて

4

あなたがトップ親としてLinearLayoutを作成し、それorientation:verticalにする必要があります。次に、最初にrelativeLayoutを追加し、TextViewを追加します。

だから、これは好きです。

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

ラップトップImageViewTextViewRelativeLayout中や使用しています。このような

何か(テストしていません):

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

いずれかを使用し、私はテストして、テキストが

と重なることはありませんので、それがあるべきRelativeLayoutより:

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

関連する問題