2

我在滚动视图和水平滚动视图的布局中使用了许多微调器。当我选择微调器布局时,会自动滚动到屏幕顶部。

下面我粘贴我的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="beforeDescendants"
        android:fillViewport="true"
        android:focusableInTouchMode="false" >

        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true" >

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/scroll_border" >

                <RelativeLayout
                    android:id="@+id/rootRelative"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:background="@drawable/contnent_border"
                    android:padding="5dp" >

                    <!-- reporter Detail layout -->

                    <LinearLayout
                        android:id="@+id/reporterLayout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >

                        <include layout="@layout/general_reporter_detail" />
                    </LinearLayout>

                    <!-- start of occurence detail tenLinear -->

                    <LinearLayout
                        android:id="@+id/occurenceDetail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/reporterLayout" >

                        <include layout="@layout/occurence_detail_flying_operation" />
                    </LinearLayout>

                </RelativeLayout>
            </RelativeLayout>
        </HorizontalScrollView>
    </ScrollView>

</LinearLayout>

如果有人对此有解决方案,请帮助我。

4

2 回答 2

0

试试这个SO answers的解决方案

它运作良好:

// save index and top position
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();

// ...

// restore
mList.setSelectionFromTop(index, top);
于 2014-09-01T08:59:03.247 回答
0

在布局中使用具有完整限定名称的自定义微调器作为默认微调器标记,并在水平滚动视图中使用此自定义微调器。它对我有用

于 2015-10-16T07:37:16.613 回答