久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果單詞對于 textview 來說太長,則強制下一個單

Force next word to a new line if the word is too long for the textview(如果單詞對于 textview 來說太長,則強制下一個單詞換行)
本文介紹了如果單詞對于 textview 來說太長,則強制下一個單詞換行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 TextView,它在以編程方式填充時不會正確地換行.

I have a TextView, that when filled programmatically will not properly line break on words.

這是正在發生的事情:

| Hi I am an examp |
| le of a string t |
| hat is not break |
| ing correctly on |
| words            |

預期輸出:

我想要這個:

| Hi I am an       |
| example of a     |
| string that is   |
| breaking         |
| correctly on     |
| words            |

Java:

String mQuestion = "Hi I am an example of a string that is breaking correctly on words";
mTextView.setText(mQuestion);

XML:

<LinearLayout
    android:id="@+id/questionContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/questionHeaderTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/header_bg"
        android:paddingBottom="10dp"
        android:paddingLeft="25dp"
        android:paddingTop="10dp"
        android:text="@string/category_hint"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Space
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".05" />

        <!-- THIS ONE WILL NOT WRAP !-->
        <TextView 
            android:id="@+id/questionHolderTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".9"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:text="@string/question_holder"
            android:singleLine="false"
            android:scrollHorizontally="false"
            android:ellipsize="none"
            android:textSize="20sp" />

        <Space
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".05" />

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="5dp"
        android:background="@color/black" />
</LinearLayout>

<LinearLayout
    android:id="@+id/answerContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="visible" >
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="25dp"
    android:gravity="center" >

    <Button
        android:id="@+id/nextButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:text="@string/next" />
</LinearLayout>

推薦答案

首先你可以使用 TextView.getPaint(),然后每次添加一個新詞(Hi, I, am, etc),調用measureText on油漆.如果結果長度比您的 TextView 的可用寬度長,請在新單詞前添加 .重置數據并重復上述步驟.

First you can get the text paint using TextView.getPaint(), then each time you add a new word(Hi, I, am, etc), call measureText on the paint. If the result length is longer than the available width of your TextView, add a before the new word.Reset the data and repeat the steps.

這篇關于如果單詞對于 textview 來說太長,則強制下一個單詞換行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 羞羞视频在线观免费观看 | 日韩免费在线 | 欧美一级大片免费观看 | 中文字幕一区二区三区在线观看 | 性高湖久久久久久久久aaaaa | 7777精品伊人久久精品影视 | 国产成人精品一区二区三区在线 | 色综久久 | 国产综合久久 | 日韩在线播放一区 | 欧美一区二区三区久久精品 | 国产精品成人一区二区 | 岛国av免费观看 | 99精品欧美一区二区三区综合在线 | 日本黄色大片免费看 | 国产免费a | 亚洲色图综合 | 99re在线视频 | 欧美成人精品欧美一级 | 国产小视频自拍 | 国产精品福利在线 | 色综合久久久久 | 午夜精品久久久久久久久久久久久 | 欧美在线一区二区三区 | 国产精品毛片无码 | 成人免费在线视频 | 99热成人在线| 天堂va在线观看 | 99精品久久99久久久久 | 日本视频一区二区三区 | 一区二区三区日韩 | 91一区二区 | 不卡的av在线| 国产激情视频网址 | 欧美一区二区三区四区视频 | 精品乱码一区二区三四区视频 | 精品国产欧美一区二区三区成人 | 日韩精品免费视频 | 成人3d动漫一区二区三区91 | 亚洲综合色婷婷 | 超碰成人免费观看 |