Android键盘调整大小问题

时间:2017-09-13 02:56:23

标签: android xml android-constraintlayout

我接手了一个Android项目。它是使用线性布局创建的。我已将其更改为ConstraintLayout。现在,在任何编辑文本中,当键盘出现时,屏幕设计正在改变。

我发现manifest.xml中有以下代码

android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"

我删除了这一行但是,当键盘出现时,我的屏幕正在调整大小。

我的简单xml设计文件如下。如果我在新项目中使用它,则没有任何调整大小问题,但我当前的项目仍然无法正常工作。

我应该看看除了设计xml和manifest.xml以外的任何地方吗?

有没有人有任何想法解决我的问题?

提前致谢。

<?xml version="1.0" encoding="utf-8"?>

<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:layout_editor_absoluteY="25dp"
    tools:layout_editor_absoluteX="0dp">



    <TextView
        android:id="@+id/txt_login_account"
        android:layout_width="287dp"
        android:layout_height="28dp"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:text="Login"
        android:textAlignment="center"
        android:textSize="24sp"
        app:layout_constraintBottom_toTopOf="@+id/imgEmailPin"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.983"
        app:layout_constraintHorizontal_bias="0.53" />

    <ImageView
        android:id="@+id/imgEmailPin"
        android:layout_width="412dp"
        android:layout_height="110dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="8dp"
        app:layout_constraintHorizontal_bias="0.833"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintVertical_bias="0.424"
        tools:layout_editor_absoluteX="-2dp" />

    <ImageView
        android:id="@+id/imgEmail"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/imgPin"
        app:layout_constraintRight_toRightOf="@+id/imgEmailPin"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.157"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_bias="0.12" />

    <TextView
        android:id="@+id/lblEmail"
        android:layout_width="60dp"
        android:layout_height="30dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="14dp"
        android:layout_marginTop="8dp"
        android:text="Email"
        android:textSize="22sp"
        app:layout_constraintBottom_toTopOf="@+id/lblPin"
        app:layout_constraintHorizontal_bias="0.22"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.100000024" />

    <EditText
        android:id="@+id/et_email"
        android:layout_width="200dp"
        android:layout_height="30dp"

        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/transparent"
        android:ems="10"
        android:inputType="textEmailAddress"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintHorizontal_bias="0.82"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.05" />

    <ImageView
        android:id="@+id/imgPin"
        android:layout_width="25dp"
        android:layout_height="25dp"
        app:srcCompat="@drawable/login"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.118"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/imgEmailPin"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.78" />

    <TextView
        android:id="@+id/lblPin"
        android:layout_width="60dp"
        android:layout_height="30dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="58dp"
        android:layout_marginTop="8dp"
        android:text="Pass"
        android:textSize="22sp"
        app:layout_constraintBottom_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintHorizontal_bias="0.1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.89" />

    <EditText
        android:id="@+id/et_pin"
        android:layout_width="200dp"
        android:layout_height="30dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="43dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="41dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/transparent"
        android:ems="10"
        android:inputType="numberPassword"
        android:textColor="@android:color/white"
        app:layout_constraintBottom_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="@+id/imgEmailPin"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.85" />


    <Button
        android:id="@+id/btn_sign_in"
        android:layout_width="264dp"
        android:layout_height="53dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="84dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="84dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif"
        android:text="Sign In"
        android:textSize="22sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.4"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.112" />

    <TextView
        android:id="@+id/lblNewUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="125dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif"
        android:text="New User"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.51"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.98" />

    <Button
        android:id="@+id/btn_sign_up"
        android:layout_width="260dp"
        android:layout_height="48dp"

        android:layout_marginBottom="8dp"
        android:layout_marginEnd="87dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="87dp"
        android:layout_marginTop="8dp"
        android:fontFamily="sans-serif"
        android:text="Save"
        android:textColor="@color/colorPrimary"
        android:textSize="22sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.43"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imgEmailPin"
        app:layout_constraintVertical_bias="0.75" />

    <Button
        android:id="@+id/tv_forgot_pin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:visibility="invisible"
        /><![CDATA[




    tools:layout_editor_absoluteX="220dp"
        tools:layout_editor_absoluteY="246dp" />


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

build.gradle依赖项:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(path: ':vector_dev_lib')
    compile project(path: ':wheelview')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.google.firebase:firebase-crash:9.6.1'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.idescout.sql:sqlscout-server:2.0'
    compile 'com.makeramen:roundedimageview:2.3.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
        transitive = true;
    }
}

1 个答案:

答案 0 :(得分:0)

  1. 好吧,就您使用ConstraintLayout添加依赖项而言: 编译'com.android.support:appcompat-v7:25.3.1'

    minSdkVersion 17

    targetSdkVersion 25

    versionCode 1

    versionName“1.0”

    testInstrumentationRunner

    “android.support.test.runner.AndroidJUnitRunner”

  2. 同步,重建项目。它应该工作