android-动态扩大视图时滚动到底部
作者:互联网
我有一个LinearLayout,并且在其中像这样膨胀CardView:
final LinearLayout itineraryDetailLL = (LinearLayout) findViewById(R.id.itineraryDetailLinearlayout);
final View childView = getLayoutInflater().inflate(R.layout.cardview, null);
itineraryDetailLL.addView(childView);
子视图的膨胀是通过单击按钮完成的.每当要放大新的Cardview时,我都想滚动到屏幕底部.我正在这样做:
ScrollView scrollview = ((ScrollView) findViewById(R.id.masterScrollView));
scrollview.fullScroll(View.FOCUS_DOWN);
但这会滚动到屏幕中间某处而不是底部.我究竟做错了什么?
解决方法:
当此ScrollView布局时,您必须发布下一帧发生的事件:
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
标签:android-layout,android-view,scrollview,android-scrollview,android 来源: https://codeday.me/bug/20191110/2014942.html