这篇文章主要介绍了android 实现ScrollView自动滚动的实例代码,有需要的朋友可以参考一下
有时候需要动态添加数据,屏幕显示满了,数据需要滚动展示。这里主要弄懂scrollTo(0, off)方法的含义喊用法。
含义不说了,大概意思就这样。
下面来看他的用法:
复制代码 代码如下:
private void searchResultShow() {
TextView textView = new TextView(AFSearchActivity.this);
textView.setText("Text View ");
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
textView.setPadding(30, 15, 0, 15);
textView.setTextSize(30);
textView.setTextColor(Color.WHITE);
//增加一个TextView到线性布局中
layout.addView(textView, p);
ImageView imageView = new ImageView(AFSearchActivity.this);
imageView.setImageResource(R.drawable.im_dottend_line);
//增加一个ImageView到线性布局中
layout.addView(imageView, p);
if(sName == null || sName.equals("")){
textView.setText("-");
}else{
textView.setText(sName);
sName = "";
mHandler.post(mScrollToBottom);
}
}
private Runnable mScrollToBottom = new Runnable()
{
@Override
public void run()
{
int off = layout.getMeasuredHeight() - nameScroll.getHeight();
if (off > 0)
{
nameScroll.scrollTo(0, off);
}
}
};
您可能感兴趣的文章:
- android开发之横向滚动/竖向滚动的ListView(固定列头)
- android实现上下滚动的TextView
- android TextView不用ScrollViewe也可以滚动的方法
- Android中实现多行、水平滚动的分页的Gridview实例源码
- Android GridView实现滚动到指定位置的方法
- android开发教程之文本框加滚动条scrollview
- Android SeekBar实现禁止滑动
- Android SeekBar实现滑动条效果
- Android自定义SeekBar滑动显示数字
- Android SeekBar实现平滑滚动