2013-08-16 5 views
1

나는 이와 같은 상대 뷰를했습니다 :텍스트 길이에 따라 상대 레이아웃의 크기를 동적으로 늘리는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linkCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/login_gradient_bg" 
     > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="6dp" 
     android:layout_marginRight="6dp" 
     android:layout_marginTop="4dp" 
     android:layout_marginBottom="4dp" 
     android:background="@drawable/card_bg"> 

     <TextView 
      android:id="@+id/linkTitle0001" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/faviconView0001" 
      android:paddingLeft="4dp" 
      android:lineSpacingExtra="-2dp" 
      android:fontFamily="sans-serif-condensed" 
      android:maxLines="2" 
      android:text="@string/link_title_001" 
      android:textColor="#717171" 
      android:textSize="17sp" /> 

     <TextView 
      android:id="@+id/linkDesc0001" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/faviconView0001" 
      android:paddingBottom="4dp" 
      android:fontFamily="sans-serif" 
      android:maxLines="1" 
      android:text="@string/link_desc_001" 
      android:textColor="#acacac" 
      android:textSize="13sp" /> 

     <ImageView 
      android:id="@+id/faviconView0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="6dp" 
      android:paddingBottom="7dp" 
      android:src="@drawable/favicon_example" /> 

     <ImageView 
      android:id="@+id/labelSource0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linkDesc0001" 
      android:background="@drawable/card_label" /> 






    </RelativeLayout> 

</FrameLayout> 

내가 linkTitle0001 텍스트 뷰에 가득 텍스트의 길이는 RelativeLayout의의 크기를 증가하고 싶었다. 어떻게해야합니까?

+0

높이를 콘텐츠를 줄 바꾸기로 설정하고 텍스트보기의 높이를 콘텐츠를 줄 바꿈으로 설정했습니다. 따라서 더 큰 문자열을 넣으면 텍스트에 맞게 자동으로 증가해야합니다. 아니면 뭔가 다른 것을 의미 했습니까? –

+0

네, 그 뜻입니다. 그러나 전혀 일어나지 않습니다. – Hick

+0

무슨 일입니까? 스크린 샷이 도움이 될 것입니다. –

답변

2
Try this: 

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linkCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/login_gradient_bg" 
     > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="6dp" 
     android:layout_marginRight="6dp" 
     android:layout_marginTop="4dp" 
     android:layout_marginBottom="4dp" 
     android:background="@drawable/card_bg"> 

     <ImageView 
      android:id="@+id/faviconView0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="6dp" 
      android:paddingBottom="7dp" 
      android:src="@drawable/favicon_example" /> 


     <TextView 
      android:id="@+id/linkTitle0001" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/faviconView0001" 
      android:paddingLeft="4dp" 
      android:lineSpacingExtra="-2dp" 
      android:fontFamily="sans-serif-condensed" 
      android:maxLines="2" 
      android:text="@string/link_title_001" 
      android:textColor="#717171" 
      android:textSize="17sp" /> 

     <TextView 
      android:id="@+id/linkDesc0001" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/faviconView0001" 
      android:paddingBottom="4dp" 
      android:fontFamily="sans-serif" 
      android:maxLines="1" 
      android:text="@string/link_desc_001" 
      android:textColor="#acacac" 
      android:textSize="13sp" /> 


     <ImageView 
      android:id="@+id/labelSource0001" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linkDesc0001" 
      android:background="@drawable/card_label" /> 

    </RelativeLayout> 

</FrameLayout> 

For Textview linkTitle0001, try to put below something or align baseline with someone as per your need. 
+0

linkTitle0001이 여전히 linkDesc0001에 겹칩니다. – Hick

+0

내 게시물의 마지막 부분에서 언급 한 내용이 있습니다. faviconView0001 오른쪽에 linkTitle0001을 (를) 배치했습니다. 그러나 당신은 그 수직 입장을 언급하지 않았습니다. faviconView0001의 오른쪽에서 원하는 경우, android : layout_alignBaseline = "@ id/faviconView0001"for linkTitle0001 – Sushil

+0

오, 예. 고마워! – Hick

0

이를 막을 규칙이 없기 때문에. source0001은 desc0001 아래에 있으며, 이는 favIcon0001 아래입니다. 제목은 favicon의 오른쪽이지만, 그 아래에있는 것들이 그것을 중첩 할 수 없다는 것을 의미하지는 않습니다. 기본적으로 layout_below는 해당 항목보다 더 이상 진행되지 않습니다. 당신은 favicon의 오른쪽으로 갈 수 없도록 (즉, 사람들이 favivon의 오른쪽으로 갈 수 없도록) 다른 모든 사람들에게 favicon을 align_right하도록하거나, 제목의 왼쪽에 배치하기 위해 모든 항목에 규칙을 넣어야합니다.

관련 문제