Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android在scrollview中滚动到下一个替换片段的顶部_Java_Android_Android Layout_Android Fragments_Android Scrollview - Fatal编程技术网

Java Android在scrollview中滚动到下一个替换片段的顶部

Java Android在scrollview中滚动到下一个替换片段的顶部,java,android,android-layout,android-fragments,android-scrollview,Java,Android,Android Layout,Android Fragments,Android Scrollview,这是我的布局: <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_pare

这是我的布局:

<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>
但我的片段不会滚动到顶部,它只会延迟工作,如:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
     @Override
     public void run() {
         mHolder.scrollView.scrollTo(0,0);
     }
}, 100);
我怎样才能以正确的方式做到这一点?我不会使用延迟添加

android:descendantFocusability="blocksDescendants"

android:descendantFocusability="blocksDescendants"
"RelativeLayout"