2012-09-06 3 views
0

나는 부모 오른쪽으로 할당 된 버튼의 왼쪽에 TextView를 배치하는 RelativeLayout을 가지고 있습니다. 따라서 TextView에 표시 할 텍스트가 wrap_Content보다 증가하면 Button에 겹칩니다. 그래서 다음 줄에 초과 된 텍스트를 표시하는 솔루션이 필요합니다. 누구든지이 문제를 해결할 수 있습니까?
아래 레이아웃에서 TextView2의 Text가 "11111111111111111111111"이면 TextView1과 겹칩니다. 어떻게 방지 할 수 있습니까?
내 레이아웃은 다음과 같습니다 다음 TextView2의 텍스트가 "11,111,111,111,111,111,111,111"는 TextView1와 중복 것 인 경우 위의 레이아웃에서 안드로이드 TextView의 너비를 동적으로 조정하는 방법

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:layout_margin="10dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/icon" > 
    </ImageView> 

    <TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView1" 
    android:layout_margin="5dp" 
    android:text="TextView" 
    android:textSize="22dp" 
    android:layout_toRightOf="@id/imageView1" 
    > 
     </TextView> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:focusable="false" 
    android:text="Button" 
    android:layout_alignTop="@+id/imageView1" 

    > 
</Button> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/button1" 
    android:text="TextView222" 
    android:textSize="22dp" 
    android:layout_margin="5dp" 
    android:layout_alignTop="@+id/imageView1" 
    android:ellipsize="end" 
    > 
</TextView> 


. 이를 방지하는 방법

답변

1

TextView에 android:layout_toLeftOf="@+id/button"을 추가하기 만하면 버튼과의 충돌을 막을 수 있습니다.

은 다음과 같이 표시됩니다

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/button" 
     android:text="11111111111111111111111111111111111111111111111111111111111111111111111111111111111"/> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:text="Potatoe"/> 

</RelativeLayout> 

당신은 질문을 변경했습니다 ...하지만 나도이 새로운 하나를 답변 해 드리겠습니다. 을 한 행에 너무 많이 넣으려는 시도 일 수 있습니다. 그러나의 수평의 LinearLayout에 레이아웃을 변경하고 부부에게 layout_weight 속성을 사용하자 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/ic_launcher"/> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:text="111111111111111111111111111111111" 
     android:textSize="22dp"/> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:ellipsize="end" 
     android:text="222222222222222222222222222222222" 
     android:textSize="22dp"/> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:text="Button"/> 

</LinearLayout> 

을 참고로 : 당신이 ellipse 속성을 사용했기 때문에 textView2 새로운 라인에 랩 어라운드하지 않습니다. 행운을 빕니다!

+0

상단에 내 레이아웃이 추가되었습니다. – user1276092

+0

위의 레이아웃에서 TextView2의 Text가 "11111111111111111111111"이면 TextView1과 겹칩니다. 어떻게 방지 할 수 있습니까? – user1276092

+0

같은 방법입니다. 하나의 TextView가 다른 TextView를 위에 쓰지 못하게하려면'layout_toLeftOf'와'layout_toRightOf'를 추가하십시오. – Sam

관련 문제