字体水平滚动

字体滚动



[功能]

当字太多的话 让字体滚动 会是一个好办法





[代码 步骤]

1. 设定 TextView 的属性

Java代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. xmlns:app="http://schemas.android.com/apk/res/com.android.View.CustomView"
4. android:orientation="vertical"
5. android:layout_width="fill_parent"
6. android:layout_height="wrap_content">
7.<TextView
8. android:id="@+id/text"
9. android:layout_width="100px"
10. android:layout_height="wrap_content"
11.
12. //居中显示
13. android:layout_centerInParent="true"
14.
15. //使得字不分行显示 否则当字太多会分行
16. android:singleLine="true"
17.
18. android:layout_x="61px"
19. android:layout_y="69px"
20.
21. //设置为"滚动"
22. android:ellipsize="marquee"
23.
24. //设置滚动时间为永远 也可以为具体的int 来设置滚动次数
25. android:marqueeRepeatLimit="marquee_forever"
26./>
27.</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.android.View.CustomView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text"
android:layout_width="100px"
android:layout_height="wrap_content"

//居中显示
android:layout_centerInParent="true"

//使得字不分行显示 否则当字太多会分行
android:singleLine="true"

android:layout_x="61px"
android:layout_y="69px"

//设置为"滚动"
android:ellipsize="marquee"

//设置滚动时间为永远 也可以为具体的int 来设置滚动次数
android:marqueeRepeatLimit="marquee_forever"
/>
</RelativeLayout>

2. 给 TextView 指定显示内容

Java代码
1.public class TextGoUsage extends Activity {
2. /** Called when the activity is first created. */
3. @Override
4. public void onCreate(Bundle savedInstanceState) {
5. super.onCreate(savedInstanceState);
6. setContentView(R.layout.main);
7.
8. TextView text = (TextView) findViewById(R.id.text);
9. text.setText("梅花绝句 闻道梅花坼晓风 雪堆遍满四山中 何方可化身千亿 一树梅花一放翁");
10. text.setTextSize(30);
11. text.setFocusable(true);
12. }
13.}
public class TextGoUsage extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TextView text = (TextView) findViewById(R.id.text);
text.setText("梅花绝句 闻道梅花坼晓风 雪堆遍满四山中 何方可化身千亿 一树梅花一放翁");
text.setTextSize(30);
text.setFocusable(true);
}
}



3. emulator 运行效果 2次时间的截图:









done!

原文地址:http://griffinshi.iteye.com/blog/585791
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值