textView 에서 텍스트 가 너무 길 게 잘 린 해결 방안
질문 설명:
텍스트 가 표시 공간 을 초과 하지 않 으 면 중력 을 위로 설정 합 니 다.
tv.setGravity(Gravity.TOP);  만약 텍스트 가 너무 범 위 를 초과 한다 면, 나 는 텍스트 의 끝 부분 을 표시 해 야 한다.
tv.setGravity(Gravity.BOTTOM);  레이아웃:
<RelativeLayout
    android:id="@+id/textLayout"
    android:layout_marginTop="16dp"
    android:layout_width="fill_parent"
    android:layout_height="110dp"
    android:orientation="vertical"
    android:visibility="visible" >
    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="top"
        android:text="Long text bla bla."
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/black"
        android:textSize="37sp" />
   ...
</RelativeLayout>  응용 프로그램 이 텍스트 의 길 이 를 어떻게 판단 해 야 할 지 모 르 겠 습 니 다.범 위 를 넘 지 않 았 습 니까?화면 마다 크기 가 다 르 기 때문에 하 드 인 코딩 을 통 해 줄 수 를 설정 하여 판단 할 수 없습니다.
해결 방안:
LinearLayout 에 TextVew 를 넣 고 TextVew 와 linearlayout 의 높이 를 비교 합 니 다.<RelativeLayout
        android:id="@+id/textLayout"
        android:layout_marginTop="16dp"
        android:layout_width="fill_parent"
        android:layout_height="110dp"
        android:orientation="vertical"
        android:visibility="visible" >
<LinearLayout 
        android:id ="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:gravity="top"
            android:text="Long text bla bla."
            android:textColor="@android:color/black"
            android:textColorHint="@android:color/black"
            android:textSize="37sp" />  비교 높이:
if(text.getHeight()>linear.getHeight()){
            //Here TextView longer than available space
        }  이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.