当显示键盘时,布局屏幕viewpager内的Scrollview不会滚动

问题描述 投票:0回答:2

我的活动布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CaretmedicinechrActivity">


    <com.badoualy.stepperindicator.StepperIndicator
        android:id="@+id/stepper_indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        app:stpi_labels="@array/stepLabels"
        app:stpi_indicatorColor="@color/Green"
        app:stpi_lineColor="@color/Blue"
        app:stpi_lineDoneColor="@color/Green"
        app:stpi_circleColor="@color/Blue"
        app:stpi_lineStrokeWidth="4dp"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/stepper_indicator" />

    <Button
        android:id="@+id/btn_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:text="@string/next"
        android:textColor="@color/black" />

    <Button
        android:id="@+id/btn_skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@null"
        android:text="@string/skip"
        android:textColor="@color/black" />


</RelativeLayout>

我的屏幕有多个edittext

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/layout1ws"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_marginTop="15dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    android:orientation="horizontal"
                    android:weightSum="2">

                    <TextView
                        android:id="@+id/textView4ws"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="5dp"
                        android:text="@string/medicinames"
                        android:layout_gravity="center_vertical"
                        android:layout_weight="1"
                        android:textSize="18sp" />


                    <EditText
                        android:id="@+id/editmdname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:background="@drawable/background_edittext"
                        android:ems="10"
                        android:inputType="textPersonName"
                        android:paddingTop="5dp"
                        android:paddingBottom="5dp" />


                </LinearLayout>


            <LinearLayout
                android:id="@+id/thbtnlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/layout1ws"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/medicintype"
                    android:textSize="18sp" />

                <Spinner
                    android:id="@+id/spinnertype"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:entries="@array/mdcinetype" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/thbtnlayout2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/thbtnlayout"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView8"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:text="@string/unit"
                    android:textSize="16sp" />

                <Spinner
                    android:id="@+id/spinnerunit"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:entries="@array/mdcineunit" />


            </LinearLayout>

            <LinearLayout
                android:id="@+id/thbtnlayout3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/thbtnlayout2"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView81"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:text="@string/medicindosage"
                    android:textSize="16sp" />

                <EditText
                    android:id="@+id/editdosage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:background="@drawable/background_edittext"
                    android:ems="10"
                    android:inputType="number"
                    android:paddingTop="5dp"
                    android:paddingBottom="5dp" />

            </LinearLayout>


            <LinearLayout
                android:id="@+id/thbtnlayout4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/thbtnlayout3"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView82"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:text="@string/medicinsession"
                    android:textSize="16sp" />

                <Spinner
                    android:id="@+id/spinnersession"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:entries="@array/mdcinesessn" />


            </LinearLayout>

            <RadioGroup
                android:id="@+id/radiogroup1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/thbtnlayout4"
                android:layout_marginStart="15dp"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/radioButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:checked="true"
                    android:text="@string/beforemeal"
                    android:textColor="@color/black"
                    android:textSize="18dp" />

                <RadioButton
                    android:id="@+id/radioButton2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/afteremeal"
                    android:textColor="@color/black"
                    android:textSize="18dp" />
            </RadioGroup>

            <LinearLayout
                android:id="@+id/thbtnlayout5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/radiogroup1"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView83"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:text="@string/description"
                    android:textSize="16sp" />

                <EditText
                    android:id="@+id/editdesc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:background="@drawable/background_edittext"
                    android:ems="10"
                    android:inputType="number"
                    android:paddingTop="5dp"
                    android:paddingBottom="5dp" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/thbtnlayout6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/thbtnlayout5"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:weightSum="2">


                <TextView
                    android:id="@+id/textView812"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:layout_weight="1"
                    android:layout_gravity="center"
                    android:text="@string/medicinetimesday"
                    android:textSize="16sp" />

                <EditText
                    android:id="@+id/editntimed"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:background="@drawable/background_edittext"
                    android:ems="10"
                    android:inputType="number"
                    android:paddingTop="5dp"
                    android:paddingBottom="5dp" />

            </LinearLayout>


        </RelativeLayout>

    </ScrollView>
</RelativeLayout>

问题是当edittext获得焦点时,键盘与edittext区域重叠,而不是滚动视图导致内容滚动。

我希望片段能够处理键盘和scrollview以适应屏幕上的键盘。

我已经尝试过这个android:windowSoftInputMode="adjustPan",但这将滚动整个活动屏幕

android android-edittext android-viewpager android-scrollview
2个回答
0
投票

在清单文件中添加此代码。根据您正在进行的活动

android:windowSoftInputMode="adjustResize|stateHidden" 

例如,如果您正在处理主要活动,它应该看起来像这样。

<activity
        android:name="com.example.MainActivity"
        android:label="@string/activity_main"
        android:windowSoftInputMode="adjustResize|stateHidden" />

0
投票

对于具有多个edittext的屏幕,将根视图设为scrollView而不是RelativeLayout并将标志放入清单android:windowSoftInputMode="adjustNothing"

© www.soinside.com 2019 - 2024. All rights reserved.