我写了一个HorizontalScrollView,是动态的添加子项,该怎么让其自动显示刚添加的子项,

mqj19910706 2012-05-07 02:31:05
我写了一个HorizontalScrollView,是动态的添加子项,该怎么让其自动显示刚添加的子项,
也就是说怎么在添加子项之后刷新显示最右面的内容
...全文
530 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
WindKun 2014-02-11
  • 打赏
  • 举报
回复
引用 5 楼 mqj19910706 的回复:
private void scrollToEnd() { new Handler().post(new Runnable() { public void run() { try { Thread.sleep(10); int left = linearLayout.getMeasuredWidth() - horizontalScrollView.getWidth(); if(left < 0) { left = 0; } horizontalScrollView.scrollTo(left, 0); } catch(Exception e) { e.printStackTrace(); } } }); } 此乃正解,仍然感谢各位!!!
那个方法是在什么地方调用的?
恶魔果实 2012-10-22
  • 打赏
  • 举报
回复
谢谢,对我非常有用,太感谢了
OopsJeff 2012-09-16
  • 打赏
  • 举报
回复
求源码~~~~
mqj19910706 2012-05-10
  • 打赏
  • 举报
回复
private void scrollToEnd() {
new Handler().post(new Runnable() {
public void run() {
try {
Thread.sleep(10);
int left = linearLayout.getMeasuredWidth() - horizontalScrollView.getWidth();
if(left < 0) {
left = 0;
}
horizontalScrollView.scrollTo(left, 0);
} catch(Exception e) {
e.printStackTrace();
}
}
});
}
此乃正解,仍然感谢各位!!!
mqj19910706 2012-05-10
  • 打赏
  • 举报
回复
private void scrollToEnd() {
new Handler().post(new Runnable() {
public void run() {
try {
Thread.sleep(10);
int left = linearLayout.getMeasuredWidth() - horizontalScrollView.getWidth();
if(left < 0) {
left = 0;
}
horizontalScrollView.scrollTo(left, 0);
} catch(Exception e) {
e.printStackTrace();
}
}
});
}
此乃正解,不过仍感谢各位!!
傲慢的上校 2012-05-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

postinvalidate方法
[/Quote]使用 postInvalidate方法,重绘UI.
小白是小菜 2012-05-07
  • 打赏
  • 举报
回复
postinvalidate方法
a-white-lie 2012-05-07
  • 打赏
  • 举报
回复
好像刷新UI的话 要借助Handler

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧