Skip to content

Commit ae42cc8

Browse files
author
玄恒
committed
update example
1 parent 664373a commit ae42cc8

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

align-text-view-example/src/main/java/me/codeboy/android/aligntextview/example/AlignTextViewExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
4949
new Handler().postDelayed(new Runnable() {
5050
@Override
5151
public void run() {
52-
alignTv.setText(text + text);
52+
alignTv.setText(text + text + text);
5353
}
5454
},5000);
5555

align-text-view-example/src/main/java/me/codeboy/android/aligntextview/example/AlignTextViewExample2.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import android.os.Bundle;
55
import android.os.Handler;
66
import android.os.Message;
7+
import android.text.method.ScrollingMovementMethod;
78
import android.view.Window;
89
import android.widget.TextView;
910

11+
import me.codeboy.android.aligntextview.AlignTextView;
1012
import me.codeboy.common.base.net.CBHttp;
1113

1214
/**
@@ -16,9 +18,11 @@
1618
*/
1719
public class AlignTextViewExample2 extends Activity {
1820

19-
TextView textViewTv;
20-
String text = "这是一段中英文混合的文本,I am very happy today." +
21-
"测试TextView文本对齐\n\nAlignTextView可以通过setAlign()方法设置每一段尾行的对齐方式,默认尾行居左对齐" +
21+
AlignTextView textViewTv;
22+
TextView textViewTv2;
23+
String text = "这是一段中英文混合的文本,I am very happy today." +
24+
"测试TextView文本对齐\n\nAlignTextView可以通过setAlign()" +
25+
"方法设置每一段尾行的对齐方式,默认尾行居左对齐" +
2226
".CBAlignTextView可以像原生TextView一样操作,但是需要使用getRealText()获取文本,欢迎访问open.codeboy.me";
2327

2428
@Override
@@ -28,29 +32,34 @@ protected void onCreate(Bundle savedInstanceState) {
2832

2933
setContentView(R.layout.align_text_view_test);
3034

31-
textViewTv = (TextView) findViewById(R.id.alignTextViewTest);
35+
textViewTv = (AlignTextView) findViewById(R.id.alignTextViewTest);
36+
textViewTv2 = (TextView) findViewById(R.id.textViewTest);
3237

3338
textViewTv.setText(text);
39+
textViewTv2.setText(text);
40+
41+
textViewTv.setMovementMethod(new ScrollingMovementMethod());
42+
textViewTv2.setMovementMethod(new ScrollingMovementMethod());
3443

3544

3645
final Handler handler = new Handler() {
3746
@Override
3847
public void dispatchMessage(Message msg) {
3948
super.dispatchMessage(msg);
4049

41-
String text = msg.getData().getString("text");
50+
// String text = msg.getData().getString("text");
4251
text = text + text;
4352
text = text + text;
4453
text = text + text;
4554
textViewTv.setText(text);
46-
55+
textViewTv2.setText(text);
4756
}
4857
};
4958

5059
new Thread() {
5160
public void run() {
5261
try {
53-
Thread.sleep(5000);
62+
Thread.sleep(3000);
5463
String text = CBHttp.getInstance().connect("http://test.codeboy.me/text")
5564
.execute();
5665
Message message = new Message();
@@ -62,5 +71,7 @@ public void run() {
6271
}
6372
}
6473
}.start();
74+
75+
6576
}
6677
}

align-text-view-example/src/main/res/layout/activity_align_text_view.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@
100100
android:layout_height="wrap_content"
101101
android:layout_alignParentBottom="true"
102102
android:layout_below="@+id/alignTextViewTitle"
103-
android:background="@drawable/red_select"
103+
android:background="@color/red2"
104104
android:padding="@dimen/view_padding"
105105
android:ellipsize="marquee"
106-
android:textIsSelectable="true"
107106
cb:align="left"
108107
android:textSize="@dimen/small_font"/>
109108
</RelativeLayout>
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<ScrollView
3+
<LinearLayout
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
6+
android:layout_height="match_parent"
7+
android:orientation="horizontal"
8+
>
79

810
<me.codeboy.android.aligntextview.AlignTextView
911
android:id="@+id/alignTextViewTest"
10-
android:layout_width="match_parent"
12+
android:layout_width="0dp"
1113
android:layout_height="wrap_content"
12-
android:background="@drawable/red_select"
14+
android:layout_weight="1"
15+
android:background="@color/red2"
1316
android:ellipsize="marquee"
17+
android:lineSpacingExtra="1dp"
18+
android:lineSpacingMultiplier="2"
19+
android:paddingBottom="10dp"
1420
android:textIsSelectable="true"
1521
android:textSize="@dimen/small_font"
16-
/>
22+
/>
23+
24+
<TextView
25+
android:id="@+id/textViewTest"
26+
android:layout_width="0dp"
27+
android:layout_height="wrap_content"
28+
android:layout_weight="1"
29+
android:background="@color/green2"
30+
android:gravity="center_vertical"
31+
android:ellipsize="marquee"
32+
android:lineSpacingExtra="1dp"
33+
android:lineSpacingMultiplier="2"
34+
android:paddingBottom="10dp"
35+
android:textIsSelectable="true"
36+
android:textSize="@dimen/small_font"
37+
/>
1738

1839

19-
</ScrollView>
40+
</LinearLayout>

0 commit comments

Comments
 (0)