android如何让ScrollView的滚动条定位到最后一行
展开全部
单独定义一个静态方法,建立一个线程判断滚动条的内层外层高度变化。
ScrollView scrollresult=(ScrollView)findViewById(R.id.scrollView);
scroll2Bottom(scrollresult, txthistroycontent);//txthistroycontent为滚动条关联的文本框
public static void scroll2Bottom(final ScrollView scroll, final View inner)
{
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (scroll == null || inner == null) {
return;
}
// 内层高度超过外层
int offset = inner.getMeasuredHeight()
- scroll.getMeasuredHeight();
if (offset < 0) {
System.out.println("定位...");
offset = 0;
}
scroll.scrollTo(0, offset);
}
});
}
}
ScrollView scrollresult=(ScrollView)findViewById(R.id.scrollView);
scroll2Bottom(scrollresult, txthistroycontent);//txthistroycontent为滚动条关联的文本框
public static void scroll2Bottom(final ScrollView scroll, final View inner)
{
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (scroll == null || inner == null) {
return;
}
// 内层高度超过外层
int offset = inner.getMeasuredHeight()
- scroll.getMeasuredHeight();
if (offset < 0) {
System.out.println("定位...");
offset = 0;
}
scroll.scrollTo(0, offset);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询