java Android在scrollview中滚动到下一个替换片段的顶部
这是我的布局:
<ScrollView xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:custom="http://schemas.安卓.com/apk/res-auto"
安卓:id="@+id/main_scrollview"
安卓:layout_width="match_parent"
安卓:scrollbars="vertical"
安卓:fillViewport="true"
安卓:layout_height="wrap_content">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginBottom="@dimen/space.small"
安卓:orientation="vertical"
安卓:padding="@dimen/space.medium">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:padding="@dimen/space.medium">
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="@string/bla_bla_bla"/>
</LinearLayout>
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:id="@+id/my_relative_layout">
</RelativeLayout>
</LinearLayout>
</ScrollView>
它是“我的选项卡”菜单中的一个片段,当创建该选项卡时,相对布局将被可变数量的元素替换:
安卓.support.v4.app.FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.my_relative_layout, myListFragment).commit();
mHolder.scrollView.scrollTo(0,0); //not work
但我的片段不会滚动到顶部,它只会延迟工作,比如:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mHolder.scrollView.scrollTo(0,0);
}
}, 100);
我怎样才能以正确的方式做到这一点?我不会耽搁的
# 1 楼答案
加上
到