xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
显示模式
android:scaleType="centerInside"
导入图片目录
android:src="@drawable/img"></ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
设置图片显示最大高宽,以最长为限制,其端等比缩放
android:maxHeight="200dp"
android:maxWidth="200dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="@drawable/img"></ImageView>
</LinearLayout>
导入图片问题
在app下的android项导入
aaptOptions.cruncherEnabled = false;
aaptOptions.useNewCruncher = false;
plugins {
id 'com.android.application'
}
android {
//这个位置
aaptOptions.cruncherEnabled = false;
aaptOptions.useNewCruncher = false;
compileSdk 31
defaultConfig {
applicationId "com.example.android_01"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
已久 冒红的话
图片命名问题(以数字开头)
图片格式不支持