android TextView 如何实现消息滚动
来源:互联网 发布:网络经营许可证申请 编辑:程序博客网 时间:2024/06/01 20:58
第一步:layout文件,主要是红色部分
<?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:weightSum="1">
<ScrollView android:layout_width="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:id="@+id/scrollView"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="10px"
android:layout_height="20dp">
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:text="第一行" android:textColor="#1A1A1A" android:background="#C1CDCD" android:textSize="13dp" android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="20dp"></TextView>
<TextView android:text="第二行" android:textColor="#1A1A1A" android:background="#C1CDCD" android:textSize="13dp" android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="20dp"></TextView>
<TextView android:text="第三行" android:textColor="#1A1A1A" android:background="#C1CDCD" android:textSize="13dp" android:id="@+id/textView3" android:layout_width="fill_parent" android:layout_height="20dp"></TextView>
<TextView android:text="第四行" android:textColor="#1A1A1A" android:background="#C1CDCD" android:textSize="13dp" android:id="@+id/textView4" android:layout_width="fill_parent" android:layout_height="20dp"></TextView>
</LinearLayout>
</ScrollView>
</LinearLayout>
第二部:Java文件
package com.exam;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.ScrollView;
public class ExampleActivity extends Activity {
/** Called when the activity is first created. */
private ScrollView scrollview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scrollview = (ScrollView) findViewById(R.id.scrollView);
scrollview.setVerticalScrollBarEnabled(false);
LooperThread mClockThread = new LooperThread();
mClockThread.start();
}
// 用于线程间通信的Handler
class TestHandler extends Handler {
public TestHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
Bundle bundle = msg.getData();
int loop = bundle.getInt("loop");
System.out.println("loop:" + loop);
if (loop == 4)
scrollview.scrollTo(0, 0);// 改变滚动条的位置
else
scrollview.scrollTo(loop * 29, loop * 29 + 30 + loop * 1);// 改变滚动条的位置
super.handleMessage(msg);
}
}
//多线程控制循环
class LooperThread extends Thread {
public void run() {
super.run();
try {
int loop = 0;
while (true) {
Thread.sleep(3000);
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putInt("loop", loop);
msg.setData(bundle);
new TestHandler(Looper.getMainLooper()).sendMessage(msg);
loop++;
if (loop == 5) {
loop = 0;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
- android TextView 如何实现消息滚动
- android----TextView如何实现无限滚动显示
- TextView 滚动如何实现
- Android中TextView如何实现水平和垂直滚动
- Android TV TextView如何实现增加滚动条
- Android TextView实现滚动效果
- Android TextView实现滚动条
- 如何让Android TextView内容滚动
- android组件TextView实现字体水平滚动
- Android TextView多行文本滚动实现
- android TextView 垂直自动滚动字幕实现
- android实现TextView垂直或水平滚动
- android 用textview实现文字滚动效果
- android TextView 垂直自动滚动字幕实现
- android TextView 垂直自动滚动字幕实现
- android TextView 垂直自动滚动字幕实现
- Android组件TextView实现字体水平滚动
- android实现TextView垂直或水平滚动
- wpf数据绑定失败
- 关系数据库一般设计流程
- zend studio用自己的apache
- Android入门第十五篇之ActivityGroup + GridView 实现Tab分页标签
- 10060与360网络优化
- android TextView 如何实现消息滚动
- extjs json grid sample(设想绑定odata数据源)
- VB.NET委托的使用
- AutoCAD中的ARX插件一般写法(ObjectARX+C++)
- 关于 Android导出apk时碰到的[Unable to execute dex: Multiple dex files define]
- Tornado: 2. 源码分析 (3)
- 严格的概念认识——关系、关系模型
- Android 与 HttpClient 通讯出现乱码问题的解决
- Objective-C: Get random number 获取随机数