约束布局在API 22中异常工作

时间:2019-01-25 18:25:02

标签: android android-layout android-constraintlayout

使用约束布局时,支持API 22的手机中的所有活动均已超出框架范围,而在22以上的其他API级别中看起来很完美,该应用程序的最低SDK级别为21。我不明白为什么会这样,因为API 22完全支持约束布局

膨胀的布局

<?xml version="1.0" encoding="utf-8"?>  
<androidx.constraintlayout.widget.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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="80dp">

<de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/user_image_recycler_inflated_main_activity"
        android:layout_width="70dp"
        android:layout_height="70dp" app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp" android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintVertical_bias="0.095"
        tools:src="@drawable/ic_person_black_24dp"
/>
<TextView
        android:layout_width="233dp"
        android:layout_height="29dp"
        android:id="@+id/username_recycler_inflated_main_activity" app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        app:layout_constraintStart_toEndOf="@+id/user_image_recycler_inflated_main_activity"
        android:layout_marginStart="8dp"
        app:layout_constraintTop_toTopOf="@+id/user_image_recycler_inflated_main_activity"
        app:layout_constraintHorizontal_bias="0.017"
        android:layout_marginTop="4dp"
        android:textColor="#000"
        android:hint="Username"
/>
<TextView
        android:layout_width="233dp"
        android:layout_height="29dp"
        android:id="@+id/email_recycler_inflated_main_activity"
        android:layout_marginStart="8dp"
        app:layout_constraintEnd_toEndOf="@+id/username_recycler_inflated_main_activity"
        android:layout_marginBottom="4dp"
        app:layout_constraintBottom_toBottomOf="@+id/user_image_recycler_inflated_main_activity"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/username_recycler_inflated_main_activity"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/username_recycler_inflated_main_activity"
        android:textColor="#000"
        android:hint="timestamp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

gradle(模块:应用)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

androidExtensions {
    experimental = true
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.two.pilots.messengerappkotlin"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

//  Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-database:16.0.5'

//  circle image view
implementation 'de.hdodenhof:circleimageview:2.2.0'

//  picasso
implementation 'com.squareup.picasso:picasso:2.71828'

//  groupie
implementation 'com.xwray:groupie:2.3.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.3.0'

//  image compressor
implementation 'id.zelory:compressor:2.1.0'

implementation 'androidx.recyclerview:recyclerview:1.0.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android-extensions'

分别为API 22,API 24,API 26

https://codesandbox.io/s/koyjjoo1y3

2 个答案:

答案 0 :(得分:0)

仅通过查看图像很难理解,但我不认为这是因为API级别,但这可能是由于您在其上测试过您的应用程序的设备之间的屏幕尺寸不同。

确保您的应用支持多种屏幕尺寸。 如果要加载图像,请确保它们适合您使用的设备分辨率,并且所有内容都受到严格限制。

答案 1 :(得分:0)

TextViews的宽度更改为0dp。 gradle没问题。问题出在布局上。它没有响应。