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

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

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

問題描述

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

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

這是正在發(fā)生的事情:

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

預(yù)期輸出:

我想要這個:

| 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),調(diào)用measureText on油漆.如果結(jié)果長度比您的 TextView 的可用寬度長,請在新單詞前添加 .重置數(shù)據(jù)并重復(fù)上述步驟.

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.

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
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 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 北条麻妃国产九九九精品小说 | 亚洲综合第一页 | 日韩一级电影免费观看 | 日韩a在线 | 久久极品 | 91免费电影| 日韩精品一区在线 | 国产中的精品av涩差av | 国产欧美日韩在线观看 | 成人影院网站ww555久久精品 | 日本精品国产 | av日韩在线播放 | 中文字幕高清免费日韩视频在线 | 欧美aaaaaaaaaa | 久艹av| 中文字幕成人av | 久久高清免费视频 | 久草视| 亚洲 欧美 日韩 精品 | 国产一级淫片a直接免费看 免费a网站 | 日韩一区二区在线看 | 亚洲一区二区日韩 | av中文字幕在线 | 色橹橹欧美在线观看视频高清 | 91色视频在线观看 | 成人啊啊啊 | 亚洲精品视频免费看 | 久久高潮| 日韩字幕| 波多野结衣一二三区 | 特一级毛片 | 中文字幕国产视频 | 九九热在线免费视频 | 亚洲综合在 | h片在线看 | 久久国内精品 | 国产美女精品 | 国产精品成人一区二区三区吃奶 | 91高清视频在线观看 | 久久国产高清 | 欧美在线 |