2016-06-22 3 views
3

LinearLayout에 TextView가 있습니다. 텍스트 뷰의 XML 우리가 텍스트로 설정 한 텍스트 뷰를 볼 수있는 권리에Android : TextView에서 이상한 텍스트 배치 문제

<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 

    android:background="@color/CLOUDS" 
    android:ellipsize="none" 
    android:maxLines="100" 
    android:minHeight="20dp" 
    android:minLines="1" 
    android:layout_margin="0dp" 
    android:paddingLeft="4dp" 
    android:paddingRight="4dp" 
    android:paddingTop="0dp" 
    android:textSize="14sp" 
    android:paddingBottom="0dp" 
    android:layout_weight="10" 
    android:layout_height="wrap_content" 
    android:layout_width="0dp" 
    android:singleLine="false" 
    android:scrollHorizontally="false" 
    android:inputType="textCapSentences|textMultiLine" 
    /> 

Error 1
: "Campanario 블랑코 \ nMistral 아이스 \ nMistral" 마지막 단어가 표시되지 않습니다.

왼쪽에는 무게가 10 인 다른 텍스트 뷰가 있습니다. 둘 다 선형 레이아웃 내에 배치됩니다.

LinearLayout linearLayout = new LinearLayout(context.mContext); 
    LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
    ll.topMargin = 2; 
    ll.bottomMargin = 0; 
    linearLayout.setOrientation(LinearLayout.HORIZONTAL); 
    linearLayout.setLayoutParams(ll); 
    linearLayout.setPadding(0, 0, 0, 0); 
    bubble.addView(linearLayout); 

가 지금은 "Campanario 블랑코 \ nMistral 아이스 \ nMistral \ nMalibu"에 대한보기의 내용을 변경하는 경우 이제 '미스트랄'표시되지만 새로운 마지막 작품 'Mailbu은'아니다. 총 라인 카운트를 나타내는 바와 같이

Error 2

는 \ n의 합이지만 고려 제 문자열의 배치를 고려하지 않는다. 긴 텍스트를 제거하면 예상대로 작동합니다. "미스트랄 아이스 \ nMistral \ nMalibu"

NO error

+0

어디에서 줄 수를 설정합니까? – jaibatrik

+0

줄 수가 없습니다. 높이를 wrap_text로 설정했습니다. 줄 수에 대한 정보는 자동 줄 바꿈이 어떻게 처리되었는지에 대한 공제입니다. – eddie

+0

이상한. 임시 해결책으로 추가 개행을 추가 할 수 있습니다. TextView와 버그? – jaibatrik

답변

0

당신은, 이런 일이이

<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="wrap_content" 
    android:layout_marginTop="20dp" 
    android:layout_marginRight="20dp" 
    android:layout_marginLeft="20dp" 
    android:padding="6dp" 
    android:background="#358576" 
    tools:context="com.example.yujcore7.myapplicationtextviewdemo.MainActivity"> 


<TextView 
    android:textColor="#fff" 
    android:textSize="20sp" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:text="Marca(s)" /> 

<TextView 
    android:textColor="#fff" 
    android:textAllCaps="true" 
    android:textSize="16sp" 
    android:layout_marginRight="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:text="Campanario Blanco\nMistral Ice\nMistral\nMalibu" /> 

사용이 레이아웃처럼 사용하고 알려 수 있습니다.

+0

감사합니다. 내 초기 레이아웃은 이와 같았습니다. 작동해야하지만 그렇지 않았습니다. 그래서 계층 구조를 보았을 때, 부모 선형 레이아웃 중 하나가 너비로 설정되었습니다 : WRAP_CONTENT 및 그 중 하나는 고정 폭을가집니다. 그래서 이상한 포장 오류가 발생했습니다. 나는 나의 대답을 업데이트했다. – eddie

0

@ swanand-vaidya 덕분에 오류가 추적되었습니다. 부모의 부모 중 하나가 wrap_content를 설정했습니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@color/WET_ASPHALT" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="270dp" 
    android:layout_height="wrap_content" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#0D97FC" 
    android:orientation="horizontal"> 

    <TextView 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:background="@color/AMETHYST_DARK" 
     android:text="line1 hello world hello world hello world hello world \nline2 hello world hello\nline 3hello world\nline4 hello world world" 
     android:textSize="14sp" /> 

</LinearLayout> 

이 레이아웃의 결과는 라인 4가 표시되지

enter image description here

이다. 맨 위 선형 레이아웃에는 wrap_conent가 있습니다.

맨 위에있는 레이아웃이 고정 값이거나 match_parent 인 경우. 모든 줄이 올바르게 표시됩니다.

관련 문제