Clicking on Edittext inside nested Scrollview scrolls outer scrollview

情到浓时终转凉″ 提交于 2019-12-11 19:01:46

问题


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>

回答1:


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?




回答2:


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

android:windowSoftInputMode="adjustResize"


来源:https://stackoverflow.com/questions/22552656/clicking-on-edittext-inside-nested-scrollview-scrolls-outer-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!