簡體   English   中英

為什么我在片段中的滾動視圖不起作用?

[英]Why my scrollview in fragment not working?

我有一個問題,我希望你們能幫助我。 我創建了一個注冊片段,當用戶在活動頁面中單擊“創建帳戶”時調用該片段。 但不知何故在片段中,滾動視圖似乎不起作用。 我無法向下滾動。 我已經嘗試了谷歌搜索的許多建議,但仍然無法正常工作。 我希望你能在我的代碼中指出我做錯了什么,以便我可以修復它。 提前謝謝你們。

這是將調用我的片段的活動:

<?xml version="1.0" encoding="utf-8"?>
<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=".ActivityLoginSignupResetPassword"
    android:animateLayoutChanges="true">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">
    </FrameLayout>

</RelativeLayout>

這是我應該可以由用戶滾動的片段:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FragmentSignup"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:focusableInTouchMode="true">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:isScrollContainer="false">

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

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/textInputLayoutEmail"
                android:hint="@string/email"
                android:theme="@style/EditTextTheme">

                <EditText
                    android:id="@+id/editTextEmail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/textInputLayoutPassword"
                android:hint="@string/password"
                app:passwordToggleEnabled="true"
                android:theme="@style/EditTextTheme">

                <EditText
                    android:id="@+id/editTextPassword"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPassword"/>
            </android.support.design.widget.TextInputLayout>

            <Button
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:id="@+id/buttonSignUp"
                android:text="@string/signup"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@drawable/btn_background_custom"
                android:textColor="@drawable/btn_text_custom"
                android:enabled="false"/>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

在嘗試了您的所有建議后,它仍然不起作用。 但是在我的清單文件中添加 'android:windowSoftInputMode="adjustResize|stateAlwaysVisible"' 之后,它就很好用了。 謝謝你。

嘗試這個:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="false">

如果您設置 layout_height 來包裝內容,則滾動視圖本身將自行調整以適應內容。 因此它無法滾動,因為就滾動視圖而言,即使它在屏幕外,它也會顯示 100% 的內容。

暫無
暫無

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

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