0

I have a parent horizontalScrollview that contains various layouts. In one particular layout there is a scrollview. Inside that scrollview there is edittext. Now when I click on any edittext for input, the horizontal scrollview automatically scrolls the screen to some other layout and I am not able to see the current active layout(containing scrollview).

I know nested scrollviews is a bad coding practice but I can not change it in this case as there will be large amount of rework. Is there any workaround for this.

Following is the xml code for main layout containing horizontalscrollview:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<HorizontalScrollView
    android:id="@+id/CloudHScrollView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>

and following is the code for one of the child layouts that is inserted later at some stage. This layout contains the scrollview which has edittexts:-

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="0dp"
    android:background="@drawable/blueoverlay"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="300dp"
        android:paddingTop="90dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/edittext"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@null"
                android:gravity="right"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@android:color/black" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>
Ethan Hunt
  • 356
  • 3
  • 17

2 Answers2

0

I'm not sure if this will work, but you can try extending outer ScrollView class and handle its onScroll events on your own.

look here:

listening to scroll events horizontalscrollview android

Android: how to listen for scrolling events?

Community
  • 1
  • 1
sygi
  • 4,288
  • 2
  • 29
  • 48
  • OnScrollChanged() callback comes when the scrolling action is done. I don't want to listen to the event after its done. I don't want the scrolling to happen at all. – Ethan Hunt Mar 21 '14 at 08:40
  • First link shows also usage of onTouch. In its listener view can decide if it wants to consume the event – sygi Mar 21 '14 at 08:57
0

I had the same issue, solved it by adding the following to AndroidManifest.xml file for the corresponding activity.

android:windowSoftInputMode="adjustResize"
Roadblock
  • 1,951
  • 2
  • 21
  • 37