Solve the problem of abnormal line change and uneven TextView of Android

Source: Internet
Author: User

Reference: Http://blog.csdn.net/u012286242/article/details/28429267?utm_source=tuicool&utm_medium=referral

About TextView exception wrapping, uneven problem analysis: Android TextView the second line starts (including the second row), each line starts with the first character cannot be letters, numbers, punctuation, and special characters, because they are half-width characters, so we want to change the half-width character to full-width character ...

:

Not converted to half-width word match either:

Convert to full-width word specifier:

Layout file: Main.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:background= "#ffffff"
android:gravity= "Center" >
<textview android:id= "@+id/content"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:textcolor= "#000000"
android:layout_marginleft= "10DP"
android:layout_marginright= "10DP"
Android:textsize= "16DP"/>
</LinearLayout>

Java file: Myactivity.java

Package com.example.androidTest;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.TextView;

public class MyActivity extends Activity {
Private TextView Content;
/**
* Called when the activity is first created.
*/
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Content= (TextView) Findviewbyid (r.id.content);
String input= "Mobile OA on-line meeting plan on May 19, 2012 9 o'clock in 102 meeting rooms on time, please attend the meeting on time! Room Quiet Identity chili powder Durex Play additional race science and technology building anti-thunder grounding Sarah will score record fast and the liberation intersection is the people are paying for the Lucas Jiefang East Road Casa! ";
String CC=TOSBC (input);
Content.settext ("+cc");
}
  Causes TextView Exception Wrapping: Android default number, letter cannot be the beginning of each line after the first line, because the number, the letter half-width character
So we just need to convert half-width characters to full-width characters, as follows
public static string TOSBC (string input) {
Char c[] = Input.tochararray ();
for (int i = 0; i < c.length; i++) {
if (c[i] = = ") {
C[i] = ' \u3000 ';
} else if (C[i] < ' \177 ') {
C[i] = (char) (C[i] + 65248);
}
}
return new String (c);
}
}

Solve the problem of abnormal line change and uneven TextView of Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.