안드로이드에서 여러 줄 TextView?
나는 아래에서 좋아했다. 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)에서 테스트
Just add textview in 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>
Simply put '\n' inside your text... no extra attribute required :)
<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"/>
I do not like the solution that forces the number of lines in the text view. I rather suggest you solve it via the solution proposed here. As I see the OP is also struggling with making text view look like proper in table and shrinkColumns
is the correct directive to pass in to achieve what is wanted.
Try to work with EditText by make it unclickable and unfocusable, also you can display a scrollbar and delete the EditText's underbar.
Here is an example:
<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 -->
/>
Hope this helps :)
First replace "\n"
with its Html
equavalent "<br>"
then call Html.fromHtml()
on the string. Follow below steps:
String text= model.getMessageBody().toString().replace("\n", "<br>")
textView.setText(Html.fromHtml(Html.fromHtml(text).toString()))
This works perfectly.
What I learned was to add "\n" in between the words where you want it to brake into the next line. For example...
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="M-F 9am-5pm \n By Appointment Only" />
The \n between 5pm and By allowed me more control of where I wanted my my next line to begin and end.
The best answer I found for multiline TextView is:
android:inputType="textMultiLine"
you can use android:inputType="textMultiLine"
<TextView android:id="@+id/address1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:maxLines="4"
android:inputType="textMultiLine"
android:text="Johar Mor, Gulistan-e-Johar, Karachi" />
I used:
TableLayout tablelayout = (TableLayout) view.findViewById(R.id.table);
tablelayout.setColumnShrinkable(1,true);
it worked for me. 1 is the number of column.
You can do this with TableRow, see below code
<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>
Why don't you declare a string instead of writing a long lines into the layout file. For this you have to declare a line of code into layout file 'android:text="@string/text"' and go to the \\app\src\main\res\values\strings.xml and add a line of code ' Your multiline text here' Also use '\n' to break the line from any point else the line will automatically be adjusted.
for me non of the solutions did not work. I know it is not a complete answer for this question, but sometimes it can help.
I put 4 textviews in a vertical linearlayout.
<Linearlayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation:"vertical"
...>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text:"line1"
.../>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text:"line2"
.../>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text:"line3"
.../>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text:"line4"
.../>
</LinearLayout>
This solution is good for cases that the text view text is constant, like labels.
TextView will be multi line when it wont get enough space to fit in the single line and singLine not set to true.
If it gets the space in one line it wont be multi line.
참고URL : https://stackoverflow.com/questions/6674578/multiline-textview-in-android
'Programing' 카테고리의 다른 글
한 클래스에서 멤버 함수와 함께 일반 std :: function 객체 사용 (0) | 2020.06.18 |
---|---|
일반 JavaScript로 프리 펜드를 추가하고 추가하려면 어떻게해야합니까? (0) | 2020.06.18 |
WcfTestClient.exe를 찾을 수있는 곳 (Visual Studio의 일부) (0) | 2020.06.18 |
PHP 문자열의 유니 코드 문자 (0) | 2020.06.18 |
목록의 마지막 항목을 제외한 모든 항목을 반복하는 방법은 무엇입니까? (0) | 2020.06.18 |