我正在制作需要滚动的屏幕,因此我在Constrainlayout中使用Nestedscrollview。
         这是我的Xml代码:

     <?xml version="1.0" encoding="utf-8"?>
      <android.support.v4.widget.NestedScrollView
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"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">


     <android.support.constraint.ConstraintLayout x
    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"
    android:background="@android:color/white"
    android:orientation="vertical">


    <android.support.v7.widget.AppCompatImageView

        android:id="@+id/ivlogo"
        android:layout_width="0dp"
        android:layout_height="140dp"

        android:layout_marginEnd="16dp"

        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/artizen"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />


    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/txt_welcomeback"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="5dp"
        android:text="@string/welcome_back"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/txt_Login"
        app:layout_constraintHorizontal_bias="0.49"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ivlogo"
        app:layout_constraintVertical_bias="0.48000002"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />


    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/txt_Login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_marginTop="30dp"
        android:text="@string/login_account"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ivlogo"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />


       <android.support.design.widget.TextInputLayout
           android:id="@+id/textInputLayout"
        android:layout_width="0dp"

        android:layout_height="48dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="30dp"
        android:textColorHint="@color/aluminum"
        android:theme="@style/EditTextHint"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/txt_Login"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1">


        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/edEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/email"
            android:inputType="textEmailAddress"
            android:singleLine="true"
            android:textSize="15sp"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp" />

    <    /android.support.design.widget.TextInputLayout>


    <android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayoutpassword"
        android:layout_width="0dp"

        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="30dp"
        android:textColorHint="@color/aluminum"
        android:theme="@style/EditTextHint"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1">

        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/edpassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/password"
            android:inputType="textEmailAddress"
            android:singleLine="true"
            android:textSize="15sp"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp" />


        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatButton
        android:id="@+id/button_login"
        android:layout_width="0dp"

        android:layout_height="48dp"
        android:layout_marginTop="40dp"
        android:background="@color/dark_yellow"
        android:text="@string/Log_in"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="@+id/textInputLayoutpassword"
        app:layout_constraintRight_toRightOf="@+id/textInputLayoutpassword"
        app:layout_constraintTop_toBottomOf="@+id/textInputLayoutpassword"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

       <android.support.v7.widget.AppCompatTextView
        android:id="@+id/txt_orlogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="@string/or_login"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button_login"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />


      <android.support.v7.widget.AppCompatImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="120dp"
        android:layout_marginStart="120dp"
        android:src="@drawable/facebook_icon"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="@+id/txt_Login"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="120dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@drawable/ic_twitter"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintRight_creator="1" />

        <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="20dp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="20dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.055555556"
        tools:layout_editor_absoluteX="20dp"
        tools:layout_editor_absoluteY="0dp" />


        </android.support.constraint.ConstraintLayout>


       </android.support.v4.widget.NestedScrollView>

最佳答案

确保ScrollView/NestedScrollView仅有一个直子。

尝试这样的事情:

 <android.support.v4.widget.NestedScrollView
....
.....>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<FrameLayout
......>
<!--Your entire content-->
........
</FrameLayout>

</ScrollView>
</android.support.constraint.ConstraintLayout>

关于android - NestedScrollView在ConstraintLayout中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42919304/

10-12 00:23