gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:22:35 26 4
gpt4 key购买 nike

在使用约束布局时,支持 API 22 的手机中的所有 Activity 都超出了框架,而在 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(模块: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

enter image description here

最佳答案

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

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

关于android - 约束布局在 API 22 中异常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54370920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com