第一步: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();
}

}
}

}


更多相关文章

  1. 分析 flutter 打包流程及 aar 产物,并将最终的 aar 集成到现有工
  2. 编译生成可执行文件(Android(安卓)studio中)并在android设备中执行
  3. Android(安卓)文件下载工具类
  4. android 源码编译报错记录
  5. Android手机中紧急号码的定制
  6. goolge 地图地址位置解析
  7. Android(安卓)UI编辑器 Unhandled event loop exception解决方法
  8. Android的adb ||开发事项及Eclipse使用
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)1.0将不支持开发蓝牙和Gtal
  2. [Android]实现静默安装APK的两种方法
  3. android studio与VS2019的安卓开发共存问
  4. android的PowerManager和PowerManager.Wa
  5. Android(安卓)Permission check的一点认
  6. 转:[Android]实现静默安装APK的两种方法
  7. [安卓基础] 003.建立你的第一个App
  8. 【30篇突击 android】源码统计 十八
  9. Android动态加载Dex技术基础
  10. 【译】使用Kotlin从零开始写一个现代Andr