久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 久久精品一区二区国产 | 黑人精品xxx一区一二区 | 日韩色综合 | av看片| 男女av网站 | 日韩黄色一级视频 | 日韩欧美在线视频观看 | 丝袜美腿亚洲综合 | 4438成人网| 国产精品毛片一区二区在线看 | 丁香激情五月 | 九九色 | 一级特黄色片 | 久久a级片 | 国内精品视频 | 五月婷婷色综合 | 国产成人精品一区二区三区在线观看 | 久久精品一区二区三区不卡牛牛 | 日韩久久av | 日本人做爰全过程 | 国模一区二区 | 狠狠操天天操 | 91欧美激情一区二区三区成人 | 久久神马 | 亚洲九九九 | 日韩精品国产精品 | 在线黄色网| 亚洲成人免费在线观看 | 国产91免费| 成人日韩在线 | 色八区| 青青草91 | 国产精品入口夜色视频大尺度 | 国产成人免费在线视频 | 91爱爱网 | 台湾av在线| 欧美九九九| 欧美日韩国产一区二区 | 欧美日韩激情 | 一区二区欧美日韩 | 在线欧美日韩 |