반응형
TextView가 1 줄보다 큰 경우 어떻게 줄임표를 표시 할 수 있습니까?
작동하지 않는 다음 레이아웃이 있습니다.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/experienceLayout"
android:background="#ffffff"
android:layout_height="match_parent"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:paddingTop="6dp">
<TextView
android:layout_weight="1"
android:id="@+id/experienceLabel"
android:text="Experience"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:textStyle="bold">
</TextView>
<TextView
android:id="@+id/experienceTextView"
android:text="TextView"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="wrap_content"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:fadeScrollbars="false">
</TextView>
</LinearLayout>
이것은 일반적인 문제입니다. 다음을 사용해보십시오.
android:scrollHorizontally="true"
android:ellipsize="end"
android:maxLines="1"
.............. 두루마리 수평으로 작동시키는 "특수 소스"입니다.
이것은 또한 타원으로 한 줄을 만듭니다.
android:singleLine="true"
이것을 사용하십시오
android:ellipsize="end"
android:singleLine="true"
어떤 출력이 나오는지 완전히 인식하지 않고 이것을 사용하지 마십시오.
android:ellipsize="end"
android:maxLines="1"
사용 maxlines = 1
하면 대부분의 문자가 잘립니다.
여러 장치 / API에서 나를 위해 일한 방식은 프로그래밍 방식으로 다음과 같았습니다 (tv는 TextView입니다).
if (tv.getLineCount() > 1) {
int lineEndIndex = tv.getLayout().getLineEnd(0);
String text = tv.getText().subSequence(0, lineEndIndex - 3) + "\u2026";
tv.setText(text);
}
따라서 위의 모든 답변은 한 줄만 표시 한 다음 줄임표가 표시되어야한다는 요구 사항을 충족합니다. 그러나 특정 텍스트 줄 뒤에 줄임표를 표시하려면 다음을 사용해야합니다.
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
With this the ellipsis will appear only after 2 lines. Note: Its important to have singleLine as false.
This helped me out:
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
Make sure the TextView
width
is set to Match_Parent
https://github.com/chrisjenx/Calligraphy/issues/43#issuecomment-523701518
반응형
'code' 카테고리의 다른 글
iPhone 응용 프로그램의 암호 필드에서 텍스트를 어떻게 가리나요? (0) | 2020.09.04 |
---|---|
Capistrano 오류 tar : tar 아카이브처럼 보이지 않습니다. (0) | 2020.09.04 |
java.net.ConnectException : localhost / 127.0.0.1 : 8080-연결이 거부되었습니다. (0) | 2020.09.04 |
Sequelize for Node를 사용하여 레코드를 업데이트하는 방법은 무엇입니까? (0) | 2020.09.04 |
마우스 오버시 이미지 이동-크롬 불투명도 문제 (0) | 2020.09.04 |