├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── README.md
├── ic_launcher-web.png
├── image
└── finalPic.jpg
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── anim
│ ├── slide_left_in.xml
│ └── slide_right_out.xml
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── emoji_29.png
│ ├── ic_launcher.png
│ └── icon.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ └── activity_main.xml
└── values
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── mtextview
├── MTextView.java
└── MainActivity.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Android_Character_Line_Feed_TextView
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Character_Line_Feed_TextView
2 | 自定义TextView,一行末尾若是英文单词,不会自动换行。
3 | 最终效果图:
4 | 
5 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/ic_launcher-web.png
--------------------------------------------------------------------------------
/image/finalPic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/image/finalPic.jpg
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 |
--------------------------------------------------------------------------------
/res/anim/slide_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
--------------------------------------------------------------------------------
/res/anim/slide_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/emoji_29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-xhdpi/emoji_29.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-xhdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuningjack/Character_Line_Feed_TextView/bded3386cad5fb149575a350b61a582473049d5d/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
16 |
17 |
21 |
22 |
23 |
27 |
28 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Android_Character_Line_Feed_TextView
5 | Hello world!
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
--------------------------------------------------------------------------------
/src/com/example/mtextview/MTextView.java:
--------------------------------------------------------------------------------
1 | package com.example.mtextview;
2 |
3 | import java.lang.ref.SoftReference;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.Comparator;
7 | import java.util.HashMap;
8 |
9 | import android.app.Activity;
10 | import android.content.Context;
11 | import android.graphics.Canvas;
12 | import android.graphics.Color;
13 | import android.graphics.Paint;
14 | import android.graphics.Paint.FontMetrics;
15 | import android.graphics.Paint.Style;
16 | import android.graphics.Rect;
17 | import android.text.Spannable;
18 | import android.text.TextPaint;
19 | import android.text.style.BackgroundColorSpan;
20 | import android.text.style.CharacterStyle;
21 | import android.text.style.DynamicDrawableSpan;
22 | import android.util.AttributeSet;
23 | import android.util.DisplayMetrics;
24 | import android.widget.TextView;
25 |
26 | /**
27 | * 图文混排TextView,请使用{@link #setMText(CharSequence)}
28 | */
29 | public class MTextView extends TextView {
30 | /**
31 | * 缓存测量过的数据
32 | */
33 | private static HashMap> measuredData =
34 | new HashMap>();
35 | private static int hashIndex = 0;
36 | /**
37 | * 存储当前文本内容,每个item为一行
38 | */
39 | ArrayList contentList = new ArrayList();
40 | private Context context;
41 | /**
42 | * 用于测量字符宽度
43 | */
44 | private TextPaint paint = new TextPaint();
45 | /**
46 | * 用于测量span高度
47 | */
48 | private Paint.FontMetricsInt mSpanFmInt = new Paint.FontMetricsInt();
49 | /**
50 | * 临时使用,以免在onDraw中反复生产新对象
51 | */
52 | private FontMetrics mFontMetrics = new FontMetrics();
53 |
54 | // private float lineSpacingMult = 0.5f;
55 | private int textColor = Color.BLACK;
56 | // 行距
57 | private float lineSpacing;
58 | private int lineSpacingDP = 5;
59 | /**
60 | * 段间距,-1为默认
61 | */
62 | private int paragraphSpacing = -1;
63 | /**
64 | * 最大宽度
65 | */
66 | private int maxWidth;
67 | /**
68 | * 只有一行时的宽度
69 | */
70 | private int oneLineWidth = -1;
71 | /**
72 | * 已绘的行中最宽的一行的宽度
73 | */
74 | private float lineWidthMax = -1;
75 | /**
76 | * 存储当前文本内容,每个item为一个字符或者一个SpanObject
77 | */
78 | private ArrayList