ScrollView实现TextView一行一行的滚动效果
2012-12-18 10:59
204 查看
在项目中因为是混合布局,TextView的宽度比较窄而内容又很多,这样用跑马灯似乎就不很合适了。。。于是,想到要一行一行的滚动TextView,这个当然要用ScrollView了,代码如下:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dip"
android:id="@+id/scrollView"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="@string/hello"
/>
</ScrollView>
可是,我的ScrollView高度比较小,手动滑动的话似乎不方便,那么就不手动滑动让它自己滑动吧。。。
如下:
xml中:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dip"
android:id="@+id/scrollView"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="@string/hello"
/>
</ScrollView>
java代码中:
public class TestScrollViewActivity extends Activity {
TextView textView ;
ScrollView scrollView;
Handler mHandler ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHandler = new Handler();
textView = (TextView) this.findViewById(R.id.textView);
scrollView = (ScrollView) this.findViewById(R.id.scrollView);
Thread t = new Thread(new Runnable(){
public void run() {
int flag = 0;
try {
Thread.sleep(1000);
while (flag < 3){
if(scrollView.getScrollY() < (textView.getHeight() - scrollView.getHeight())){
System.out.println("");
System.out.println("scrollView.getScrollY() ====== " + scrollView.getScrollY());
mHandler.post(new Runnable(){
public void run() {
scrollView.smoothScrollBy(0, textView.getLineHeight()/10);
}
});
Thread.sleep(100);
}else{
mHandler.post(new Runnable(){
public void run() {
scrollView.smoothScrollTo(0, 0);
System.out.println("--- else ---------");
}
});
Thread.sleep(1000);
flag ++ ;
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
t.start();
}
}
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dip"
android:id="@+id/scrollView"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="@string/hello"
/>
</ScrollView>
可是,我的ScrollView高度比较小,手动滑动的话似乎不方便,那么就不手动滑动让它自己滑动吧。。。
如下:
xml中:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="100dip"
android:id="@+id/scrollView"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="@string/hello"
/>
</ScrollView>
java代码中:
public class TestScrollViewActivity extends Activity {
TextView textView ;
ScrollView scrollView;
Handler mHandler ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHandler = new Handler();
textView = (TextView) this.findViewById(R.id.textView);
scrollView = (ScrollView) this.findViewById(R.id.scrollView);
Thread t = new Thread(new Runnable(){
public void run() {
int flag = 0;
try {
Thread.sleep(1000);
while (flag < 3){
if(scrollView.getScrollY() < (textView.getHeight() - scrollView.getHeight())){
System.out.println("");
System.out.println("scrollView.getScrollY() ====== " + scrollView.getScrollY());
mHandler.post(new Runnable(){
public void run() {
scrollView.smoothScrollBy(0, textView.getLineHeight()/10);
}
});
Thread.sleep(100);
}else{
mHandler.post(new Runnable(){
public void run() {
scrollView.smoothScrollTo(0, 0);
System.out.println("--- else ---------");
}
});
Thread.sleep(1000);
flag ++ ;
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
t.start();
}
}
相关文章推荐
- TextView实现滚动效果
- Android自定义textview实现竖直滚动跑马灯效果
- (五十)TextView文本滚动效果实现
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行?
- 自定义View—实现滚动TextView(跑马灯)效果
- TextView 的ScrollView滚动效果
- TextView单行显示,文字左右滚动(走马灯效果)实现条件:
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行?
- 文本内容超过TextView的长度时,实现文本内容水平滚动效果
- Android系统中TextView实现滚动效果
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行
- android TextView实现滚动显示效果
- 实现TextView的垂直滚动,更新文字时自动滚动到最后一行
- TextView实现文字的滚动效果
- Android textview和listview实现水平自动滚动的走马灯效果
- android TextView实现实现跑马灯效果,并监听滚动完成动作。
- 实现TextView的垂直滚动,更新文字时自动滚动到最后一行
- TextView布局文件中实现文本过长时滚动显示效果
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行
- Android Textview实现颜色渐变滚动效果