使用ConstraintsLayout滚动(ScrollView)整个布局,不打开操作栏,全屏和键盘

时间:2017-05-04 19:29:22

标签: android

当软键盘打开时,我无法滚动整个布局。以下代码在没有键盘的情况下正常工作但是当键盘打开时他无法动摇整个活动。在这里我的清单:

<activity android:name=".Add"
    android:screenOrientation="sensorPortrait"
    android:windowSoftInputMode="stateHidden"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>

在我的xml活动中,我没有找到ConstraintsLayout的样本:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/custom_background"
    android:clipToPadding="false"
    android:fillViewport="true"
    android:screenOrientation="portrait"
    android:paddingBottom="0dp">


    <android.support.constraint.ConstraintLayout 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="rapture.engineering.wareapp.MainActivity">


        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/background_shape"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="1.0">

        </RelativeLayout>

        <TextView
            android:id="@+id/textView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="32dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="16dp"
            android:text="Title"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintTop_toBottomOf="@+id/add_snap" />


        <ImageView
            android:id="@+id/add_snap"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="24dp"
            android:background="@drawable/image_not_available"
            android:scaleType="fitXY"
            app:layout_constraintDimensionRatio="w,1:1"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp" />


        <android.support.constraint.Guideline
            android:id="@+id/guideline4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.05"
            tools:layout_editor_absoluteY="25dp"
            tools:layout_editor_absoluteX="18dp" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.95"
            tools:layout_editor_absoluteY="25dp"
            tools:layout_editor_absoluteX="342dp" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.5"
            tools:layout_editor_absoluteY="25dp"
            tools:layout_editor_absoluteX="180dp" />

        <EditText
            android:id="@+id/add_title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginRight="32dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/custom_edit_text"
            android:ems="10"
            android:imeOptions="flagNoExtractUi"
            android:inputType="textPersonName"
            android:padding="5dp"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toBottomOf="@+id/textView"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="25dp"
            android:text="Description"
            android:textColor="@android:color/black"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintTop_toBottomOf="@+id/add_title"
            android:layout_marginStart="32dp" />

        <EditText
            android:id="@+id/add_description"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginRight="32dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/custom_edit_text"
            android:ems="10"
            android:gravity="top|left"
            android:imeOptions="flagNoExtractUi"
            android:inputType="textMultiLine"
            android:maxLines="10"
            android:minLines="5"
            android:padding="5dp"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toBottomOf="@+id/textView2"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="25dp"
            android:text="Quantity"
            android:textColor="@android:color/black"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintTop_toBottomOf="@+id/add_description"
            android:layout_marginStart="32dp" />

        <EditText
            android:id="@+id/add_quantity"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/custom_edit_text"
            android:ems="10"
            android:imeOptions="flagNoExtractUi"
            android:inputType="number"
            android:padding="5dp"
            android:text="1"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline6"
            app:layout_constraintTop_toBottomOf="@+id/textView3"
            android:layout_marginStart="32dp" />

        <ImageButton
            android:id="@+id/add_minus"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginLeft="8dp"
            android:background="@android:color/transparent"
            android:scaleType="fitXY"
            app:layout_constraintBottom_toBottomOf="@+id/add_quantity"
            app:layout_constraintDimensionRatio="h,1:1"
            app:layout_constraintLeft_toRightOf="@+id/add_quantity"
            app:layout_constraintTop_toTopOf="@+id/add_quantity"
            app:layout_constraintVertical_bias="0.0"
            app:srcCompat="@drawable/minus"
            android:layout_marginStart="8dp" />

        <ImageButton
            android:id="@+id/add_plus"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:background="@android:color/transparent"
            android:scaleType="fitXY"
            app:layout_constraintBottom_toBottomOf="@+id/add_minus"
            app:layout_constraintDimensionRatio="h,1:1"
            app:layout_constraintLeft_toRightOf="@+id/add_minus"
            app:layout_constraintTop_toTopOf="@+id/add_minus"
            app:srcCompat="@drawable/plus" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginTop="24dp"
            android:text="Position"
            android:textColor="@android:color/black"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintTop_toBottomOf="@+id/add_quantity"
            android:layout_marginStart="32dp" />

        <EditText
            android:id="@+id/add_position"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="32dp"
            android:layout_marginRight="32dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/custom_edit_text"
            android:ems="10"
            android:imeOptions="flagNoExtractUi"
            android:inputType="textPersonName"
            android:padding="5dp"
            android:textColor="@android:color/black"
            android:textSize="14sp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toBottomOf="@+id/textView4"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp" />

        <ImageButton
            android:id="@+id/add_save"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="32dp"
            android:background="@android:color/transparent"
            android:scaleType="fitXY"
            app:layout_constraintDimensionRatio="w,1:1"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline4"
            app:layout_constraintRight_toLeftOf="@+id/guideline6"
            app:layout_constraintTop_toBottomOf="@+id/add_position"
            app:srcCompat="@drawable/save"
            android:layout_marginStart="24dp"
            android:layout_marginEnd="24dp" />

        <ImageButton
            android:id="@+id/add_delete"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="32dp"
            android:background="@android:color/transparent"
            android:scaleType="fitXY"
            app:layout_constraintDimensionRatio="w,1:1"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/guideline6"
            app:layout_constraintRight_toLeftOf="@+id/guideline5"
            app:layout_constraintTop_toBottomOf="@+id/add_position"
            app:srcCompat="@drawable/delete"
            android:layout_marginStart="24dp"
            android:layout_marginEnd="24dp" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="30dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            android:background="@android:color/transparent"
            app:layout_constraintLeft_toLeftOf="@+id/add_save"
            app:layout_constraintRight_toRightOf="@+id/add_delete"
            app:layout_constraintTop_toBottomOf="@+id/add_save" />
    </android.support.constraint.ConstraintLayout>
</ScrollView>

为了重新创建项目,这里是@ drawable / background_shape的代码:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#F9F9F9"/>
    <stroke android:width="3dip" android:color="#007fff" />
    <corners android:radius="10dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

0 个答案:

没有答案