안드로이드에서 여러 줄 TextView? android:layout_height=”wrap_content”

나는 아래에서 좋아했다. xml

<TableRow>
    <TextView android:id="@+id/address1"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:gravity="left"
        android:maxLines="4" 
        android:singleLine="false"              
        android:text="Johar Mor, Gulistan-e-Johar, Karachi" >
    </TextView> 
</TableRow>

그것은 작동하지 않으며 multiline사용하고 있습니다 TableLayout

내가 여기서하는 실수는 무엇입니까?



답변

넣는 텍스트 TextView가 짧으면 자동으로 4 줄로 확장되지 않습니다. 당신이 원하는 경우 TextView합니다 항상 관계없이 설정이 텍스트의 길이의 네 줄이 android:lines속성 :

<TextView
    android:id="@+id/address1"
    android:gravity="left"
    android:layout_height="fill_parent"
    android:layout_width="wrap_content"
    android:maxLines="4"
    android:lines="4"
    android:text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."></TextView>

TableRow를 사용 하여이 작업을 수행 할 수 있습니다. 아래 코드를 참조하십시오.

<TableRow >
        <TextView
            android:id="@+id/tv_description_heading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="8dp"
            android:text="@string/rating_review"
            android:textColor="@color/black"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tv_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:maxLines="4"`enter code here`
            android:padding="8dp"
            android:text="The food test was very good."
            android:textColor="@color/black"
            android:textColorHint="@color/hint_text_color" />
    </TableRow>

답변

방금 다음을 사용하면 추가한다고 생각했습니다.

android:inputType="textMultiLine"

그런 다음보기를 클릭 할 수 없게됩니다. 클릭에 반응해야하는 슬라이드 드로어 메뉴에서 여러 줄의 텍스트 뷰를 얻으려고했습니다.

android:singleLine="false"일을 잘하지만.


답변

나는 어느 대답도 좋아하지 않는다. inputType을 설정하면 TextView가 내용에 맞게 조정됩니다.

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"/>

Nexus One (2.3) 및 Nexus 4 (4.4)에서 테스트


답변

텍스트 안에 ‘\ n’을 넣으면 추가 속성이 필요하지 않습니다. 🙂

          <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Pigeon\nControl\nServices"
            android:id="@+id/textView5"
            android:layout_gravity="center"
            android:paddingLeft="12dp"/> 

답변

ScrollView에 텍스트보기를 추가하십시오.

<ScrollView
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:layout_marginLeft="15dp"
           android:layout_marginRight="15dp"
           android:layout_marginTop="20dp"
           android:fillViewport="true">

           <TextView
               android:id="@+id/txtquestion"
               android:layout_width="fill_parent"
               android:layout_height="match_parent"
               android:background="@drawable/abs__dialog_full_holo_light"
               android:lines="20"
               android:scrollHorizontally="false"
               android:scrollbars="vertical"
               android:textSize="15sp" />

       </ScrollView>

답변

텍스트보기에서 줄 수를 강제로 지정하는 솔루션이 마음에 들지 않습니다. 오히려 여기에 제안 된 솔루션을 통해 해결하는 것이 좋습니다 . 알다시피 OP는 테이블에서 텍스트보기를 적절하게 보이게 만드는 데 어려움을 겪고 있으며 shrinkColumns원하는 것을 달성하기 위해 전달 해야하는 올바른 지시어입니다.


답변

클릭 할 수없고 초점을 맞출 수 없도록하여 EditText로 작업 해보십시오. 또한 스크롤 막대를 표시하고 EditText의 언더 바를 삭제할 수 있습니다.
예를 들면 다음과 같습니다.

<EditText
android:id="@+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:inputType="textMultiLine"                   <!-- multiline -->
android:clickable="false"                         <!-- unclickable -->
android:focusable="false"                         <!-- unfocusable -->
android:scrollbars="vertical"     <!-- enable scrolling vertically -->
android:background="@android:color/transparent"   <!-- hide the underbar of EditText -->
/>  

도움이 되었기를 바랍니다 🙂