为什么片段中的滚动视图不起作用?

时间:2018-09-19 15:16:35

标签: android xml

我有一个问题,希望你们能帮助我。我创建一个注册片段,当用户在活动页面中单击“创建帐户”时会调用该片段。但是在某种程度上,scrollview似乎无法正常工作。我无法向下滚动。我尝试了谷歌搜索的许多建议,但仍然无法正常工作。希望您能在我的代码中指出我做错了什么,以便我可以解决。预先谢谢你们。

这是将调用我的片段的活动:

<?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>

2 个答案:

答案 0 :(得分:1)

尝试一下:

UINavigationBar.appearance().barTintColor = UIColor(red: 240/255, green: 224/255, blue: 227/255, alpha: 1)
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
   UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "Cardo-Regular", size: 22)!]
   UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: "Cardo-Regular", size: 20)!], for: UIControlState.normal)

如果您设置layout_height来包装内容,那么scrollview本身将自行包裹以适合内容。因此,它无法滚动,因为就滚动视图而言,即使不在屏幕上,它也将显示100%的内容。

答案 1 :(得分:1)

尝试了所有建议后,仍然无法使用。但是在清单文件中添加“ android:windowSoftInputMode =“ adjustResize | stateAlwaysVisible”“之后,它的效果很好。谢谢。

相关问题