2016-10-09 6 views
1

Android TextView 및 ellipsize 속성에서 이상한 동작을 발견했습니다. 텍스트가 길고 ellipsize 특성이 적용되면 텍스트의 원래 위치가 손실되고 텍스트가 조금 더 위에 표시됩니다.ellipsize 속성이 원래 위치에서 이동 한 Android TextView

예, 프로그래밍으로 해결할 수 있지만 버그가 될 수 있는지 또는 잘못된 것이 있는지 알고 싶습니다.

아주 간단한 예제입니다. 두 개의 textview의 텍스트를 변경하여 마지막 스크린 샷에 텍스트가 줄이 보이지 않거나 보이지 않게하십시오. 스크린 샷을 비교하면 문제가 표시됩니다.

'dp'및 'sp'로 테스트하여 다른 동작이 가능한지 확인했습니다. 그러나 그렇지 않습니다.

Short texts under the blocks color perfectly glued

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white"> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="50dp" 
     android:background="@android:color/holo_green_dark" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="23.3dp" 
     android:ellipsize="end" 
     android:maxLines="1" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:text="Hello World! (dp textSize)" 
     android:textColor="@android:color/black" 
     android:textSize="25dp" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="150dp" 
     android:background="@android:color/holo_blue_dark" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="123.2dp" 
     android:ellipsize="end" 
     android:maxLines="1" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:text="Hello World! (sp textSize)" 
     android:textColor="@android:color/black" 
     android:textSize="25sp" /> 

</RelativeLayout> 

Simply changing the texts with a long string and the texts aren't perfectly glued

SOLUTION :

용액 사라질 속성 '만일 Singleline'다음 문제를 사용하는 것이다. 하지만 AndroidStudio에서는 'singleLine이 사용되지 않습니다'라고 알려줍니다.

+0

해결책은 'singleLine'특성을 사용하고 문제가 사라집니다. 하지만 AndroidStudio에서는 'singleLine이 사용되지 않습니다'라고 알려줍니다. – aLxnophis

답변

1

"Courier New"와 비슷한 문제가 있었는데, 1 줄짜리 줄이 줄임표가 찍히면 몇 픽셀 아래로 이동했습니다.

android:includeFontPadding="false" 

을 내가 해당 글꼴을 사용 어디든지 : 내 문제에 대한 해결책은 추가했다.

+0

이 옵션을 살펴 보겠습니다. 감사! – aLxnophis