TextViews
에세트의 힌트가 설정되어 있고 TextView
에 입력 된 텍스트의 너비가 너비만큼 넓지 않은 경우 -text이면 TextView
은 텍스트를 감싸기 위해 너비를 변경하지 않습니다. 그러나 입력 된 텍스트가 힌트 텍스트의 너비보다 넓고 TextView
의 넓이가있는 경우 텍스트가 줄 바꿈됩니다.TextView에서 너비를 Android에서 텍스트의 너비로 변경하는 방법
이상적으로는 TextView
이 힌트 텍스트의 너비 (원래 너비는 TextView
)에 관계없이 내 텍스트로 축소되는 것이 가장 이상적이지만, 내 텍스트의 너비는 이니, 그 너비 인 TextView
에서 setWidth
으로 전화하면됩니다.
이미 초기화 후 TextView
의 최소 너비를 0으로 변경하려고 시도했지만 문제가 해결되지 않습니다. 재미있는 점은 힌트 텍스트보다 더 넓은 텍스트를 입력하면 텍스트에서 문자를 가져 와서 힌트 텍스트가 가져야하는 너비가 될 때까지 축소됩니다. . 내가 원했던 것은 힌트 텍스트의 너비에 관계없이 항상 텍스트의 너비로 축소되는 것입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/month_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="mm"
android:textColorHint="@color/hint_color"
android:singleLine="true"
android:textSize="40sp"
android:maxLength="2"/>
<TextView
android:id="@+id/first_hypen_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="-"
android:singleLine="true"
android:textSize="40sp"/>
<TextView
android:id="@+id/day_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="dd"
android:textColorHint="@color/hint_color"
android:singleLine="true"
android:textSize="40sp"
android:maxLength="2"/>
<TextView
android:id="@+id/second_hyphen_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="-"
android:singleLine="true"
android:textSize="40sp"/>
<TextView
android:id="@+id/year_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="yyyy"
android:textColorHint="@color/hint_color"
android:singleLine="true"
android:textSize="40sp"
android:maxLength="4"/>
</LinearLayout>
TextView에 'android : singleLine = "true"'를 추가하십시오. 도움이 되나요? – Vikrant
@Vikrant는 이미 그걸 가지고 있습니다. – shoe
전체 XML 레이아웃을 표시 – user1506104