2

I am using about many spinner in layout in scrollview and horizontal scrollview. when i do selection of spinner layout scroll automatically to top of the screen.

below i paste my layout

<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>

if anyone have a solution for this please help me.

Malik Umar
  • 582
  • 3
  • 13
Hardik Nadiyapara
  • 2,406
  • 2
  • 14
  • 24

2 Answers2

0

try the solution from this SO answers

it works well:

// 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);
Community
  • 1
  • 1
dvrm
  • 3,781
  • 4
  • 32
  • 44
0

use a custom spinner in layout with full qualified name as intead of defult spinner tag and use this custom spinner in horizontal scrollview.it worked for me

sud
  • 505
  • 1
  • 4
  • 12
  • Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Oct 16 '15 at 07:53