【发布时间】:2019-01-25 18:25:01
【问题描述】:
在使用约束布局时,支持 API 22 的手机中的所有活动都超出了框架,而在其他 API 级别高于 22 的情况下看起来很完美。应用的最低 SDK 级别为 21。我不明白为什么会发生这种情况,因为 API 22 完全支持 Constraint Layout。
膨胀的布局
<?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(Module:app)
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
【问题讨论】:
-
有关您的布局的一些信息会有所帮助。很难仅在图像上进行调试。
-
@Cheticamp 请查看编辑
-
结束标签在哪里?
-
我什么都没有。尝试回退到
ConstraintLayout的生产版本,例如1.1.3。您可能在 2.0.0-alpha03 版本中遇到问题。 -
已将
Constraint Layout版本更改为 1.1.3 但仍然存在此问题。我在其他具有不同 API 级别的真实设备上运行此应用程序,发现此问题仅发生在真实设备上,而与 API 级别无关。
标签: android android-layout android-constraintlayout