簡體   English   中英

android-ScrollView不會在鍵盤向上滾動

[英]android - ScrollView doesn't scroll when keyboard is up

我在Android Studio中有以下xml文件:

activity_register.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/register"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="mk.klikniobrok.klikniobrok.RegisterActivity">

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="48dp">


        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/layout_top_margin"
            android:orientation="vertical"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

            <LinearLayout
                android:id="@+id/input"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:orientation="vertical">


                <EditText
                    android:id="@+id/name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/name_hint"
                    android:inputType="text"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

                <EditText
                    android:id="@+id/username"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/user_hint"
                    android:inputType="text"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/pass_hint"
                    android:inputType="textPassword"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

                <EditText
                    android:id="@+id/repeatPwd"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/repeatPwd_hint"
                    android:inputType="textPassword"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

                <EditText
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/email_hint"
                    android:inputType="textEmailAddress"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

                <EditText
                    android:id="@+id/phone"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/phone_hint"
                    android:inputType="phone"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:textSize="@dimen/input_text_size" />

            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        android:gravity="end"
        android:orientation="horizontal"
        android:paddingBottom="2dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingTop="2dp">

        <Button
            android:id="@+id/registerButton"
            style="@style/RobotoBoldButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/ripple_transparent"
            android:text="РЕГИСТРИРАЈ СЕ"
            android:textSize="16sp" />
    </LinearLayout>
</RelativeLayout>

當鍵盤沒有抬起時,我可以看到每個元素,但是每當鍵盤抬起時,ScrollView不會向下滾動以顯示覆蓋的元素。 我已閱讀StackOverflow並將android:windowSoftInputMode =“ stateHidden | adjustResize”添加到AndroidManifest.xml中,但仍然無法正常工作。

碰巧是什么問題,我該如何解決?

請嘗試在根元素上設置android:layout_height="match_parent"

您的根元素具有android:layout_height="wrap_content" (根據您的孩子計算身高),而主要孩子具有android:layout_height="match_parent" (根據您的父母計算身高)。 它看起來像是雞肉和雞蛋的問題,我想這就是為什么它可以在某些設備上運行,而在某些其他設備上卻不行的原因。

老實說,我還沒有嘗試過是否可行,但這就是我得出的結論。 如果沒有幫助,我再看一看。

已修復,問題是在LinearLayout中使用了上邊距而不是為元素填充,這顯然是一個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM