this is my layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_scrollview"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:fillViewport="true"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/space.small"
android:orientation="vertical"
android:padding="@dimen/space.medium">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/space.medium">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bla_bla_bla"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_relative_layout">
</RelativeLayout>
</LinearLayout>
</ScrollView>
it is a fragment inside my tab menu, when this tab will be create the relative layout will be replaced by a variable number of elements:
android.support.v4.app.FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.my_relative_layout, myListFragment).commit();
mHolder.scrollView.scrollTo(0,0); //not work
But my fragment doesn't scroll to top, it works only with a delay like:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mHolder.scrollView.scrollTo(0,0);
}
}, 100);
How can I do that in a right way? I won't use a delay