i_m*_*ine 10 java xml android textview
我有一个TextView,当以编程方式填充时,将无法正确划分单词.
这就是发生的事情:
| Hi I am an examp |
| le of a string t |
| hat is not break |
| ing correctly on |
| words |
Run Code Online (Sandbox Code Playgroud)
我要这个:
| Hi I am an |
| example of a |
| string that is |
| breaking |
| correctly on |
| words |
Run Code Online (Sandbox Code Playgroud)
String mQuestion = "Hi I am an example of a string that is breaking correctly on words";
mTextView.setText(mQuestion);
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
首先你可以使用文本绘画TextView.getPaint(),然后每次添加一个新单词(嗨,我,我等),调用measureText绘画.如果结果长度超过TextView的可用宽度,请\n在新单词之前添加一个.重置数据并重复这些步骤.
| 归档时间: |
|
| 查看次数: |
8652 次 |
| 最近记录: |