Android ConstraintLayout ScrollView не прокручивается - PullRequest
0 голосов
/ 12 января 2020

У меня есть этот макет, но он не прокручивается.

Я хочу сделать изображение больше экрана устройства (он же 1440x3040 xxhdpi).

Поэтому я установил scrollVeiw android:layout_height="1453dp" , (это число взято с zeplin dashboard)

Если я установлю scrollVeiw в android:layout_height="match_parent", это сделает вид слишком коротким. посмотреть изображение дизайна

Вот мой xml код

<ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="match_parent"
    android:layout_height="1453dp"
    android:fillViewport="true"
    app:layout_constraintTop_toTopOf="parent"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_name_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.4068" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_email_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.4782" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_pwd_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.5495" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_pwd_chk_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.6208" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_member_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.2547" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_member_img_change_btn_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.3284" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_member_img_change_btn_vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.5972" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline_email_login_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.9062" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ems="10"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.2009"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintWidth_percent="1.0"
            app:srcCompat="@color/colorAccent" />

        <EditText
            android:id="@+id/name_text"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:drawableLeft="@mipmap/name"
            android:ems="10"
            android:inputType="textPersonName"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.04"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_name_text"
            app:layout_constraintWidth_percent="0.8" />

        <EditText
            android:id="@+id/email_text"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ems="10"
            android:inputType="textEmailAddress"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.04"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_email_text"
            app:layout_constraintWidth_percent="0.8" />

        <EditText
            android:id="@+id/pwd_text"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ems="10"
            android:inputType="textPassword"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.04"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"

            app:layout_constraintTop_toTopOf="@+id/guideline_pwd_text"
            app:layout_constraintWidth_percent="0.8"

            />

        <EditText
            android:id="@+id/pwd_chk_text"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:drawableLeft="@mipmap/name"
            android:ems="10"
            android:inputType="textPassword"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.04"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_pwd_chk_text"
            app:layout_constraintWidth_percent="0.8" />

        <ImageButton
            android:id="@+id/email_login_button"
            android:layout_width="0dp"
            android:layout_height="0dp"

            android:ems="10"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.0474"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_email_login_btn"
            app:layout_constraintWidth_percent="0.5568"
            app:srcCompat="@mipmap/signin_btn" />

        <ImageView
            android:id="@+id/member_img"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ems="10"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.1028"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_member_img"
            app:layout_constraintWidth_percent="0.3806"
            app:srcCompat="@mipmap/person" />

        <ImageButton
            android:id="@+id/member_img_change_btn"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ems="10"
            app:layout_constrainedHeight="true"
            app:layout_constrainedWidth="true"

            app:layout_constraintHeight_percent="0.0282"
            app:layout_constraintStart_toStartOf="@+id/guideline_member_img_change_btn_vertical"
            app:layout_constraintTop_toTopOf="@+id/guideline_member_img_change_btn_horizontal"
            app:layout_constraintWidth_percent="0.3068"
            app:srcCompat="@mipmap/change_image" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Ответы [ 3 ]

0 голосов
/ 12 января 2020

Установите фиксированную высоту (1453dp) для ConstraintLayout и установите высоту ScrollView match_parent:

<ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_constraintTop_toTopOf="parent"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="1453dp">

        ...

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
0 голосов
/ 12 января 2020

Попробуйте использовать NestedScrollView вместо scrollview

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="700dp">

    </android.support.constraint.ConstraintLayout>

0 голосов
/ 12 января 2020

РЕШЕНИЕ:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/layout1"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <ScrollView
                android:id="@+id/scrollView2"
                android:layout_width="match_parent"
                android:layout_height="1453dp"
                android:fillViewport="true"
                app:layout_constraintTop_toTopOf="parent"
                >

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_name_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.4068" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_email_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.4782" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_pwd_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.5495" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_pwd_chk_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.6208" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_member_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.2547" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_member_img_change_btn_horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.3284" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_member_img_change_btn_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.5972" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_email_login_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.9062" />

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:ems="10"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.2009"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintWidth_percent="1.0"
                app:srcCompat="@color/colorAccent" />

            <EditText
                android:id="@+id/name_text"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:drawableLeft="@mipmap/name"
                android:ems="10"
                android:inputType="textPersonName"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.04"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/guideline_name_text"
                app:layout_constraintWidth_percent="0.8" />

            <EditText
                android:id="@+id/email_text"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:ems="10"
                android:inputType="textEmailAddress"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.04"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/guideline_email_text"
                app:layout_constraintWidth_percent="0.8" />

            <EditText
                android:id="@+id/pwd_text"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:ems="10"
                android:inputType="textPassword"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.04"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"

                app:layout_constraintTop_toTopOf="@+id/guideline_pwd_text"
                app:layout_constraintWidth_percent="0.8"

                />

            <EditText
                android:id="@+id/pwd_chk_text"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:drawableLeft="@mipmap/name"
                android:ems="10"
                android:inputType="textPassword"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.04"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/guideline_pwd_chk_text"
                app:layout_constraintWidth_percent="0.8" />

            <ImageButton
                android:id="@+id/email_login_button"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:ems="10"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.0474"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/guideline_email_login_btn"
                app:layout_constraintWidth_percent="0.5568"
                app:srcCompat="@mipmap/signin_btn" />

            <ImageView
                android:id="@+id/member_img"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:ems="10"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHeight_percent="0.1028"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/guideline_member_img"
                app:layout_constraintWidth_percent="0.3806"
                app:srcCompat="@mipmap/person" />

            <ImageButton
                android:id="@+id/member_img_change_btn"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:ems="10"
                app:layout_constrainedHeight="true"
                app:layout_constrainedWidth="true"

                app:layout_constraintHeight_percent="0.0282"
                app:layout_constraintStart_toStartOf="@+id/guideline_member_img_change_btn_vertical"
                app:layout_constraintTop_toTopOf="@+id/guideline_member_img_change_btn_horizontal"
                app:layout_constraintWidth_percent="0.3068"
                app:srcCompat="@mipmap/change_image" />

            </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...