我有一个LaunchActivity,在这个Activity中有一个居中的ImageView。我有一个不同密度的PNG。问题是当我通过Glide加载我的可绘制PNG时,和当我在ImageView中简单地将其定义为android:src="@drawable/my_splash_logo"
来使用它时,两者之间存在大小差异。
这里你可以看到我的LaunchActivity.kt:
class LaunchActivity : AppCompatActivity() {
lateinit var newSplashScreen: SplashScreen
override fun onCreate(savedInstanceState: Bundle?) {
newSplashScreen = installSplashScreen()
overridePendingTransition(0, 0)
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.activity_launch)
setupStatusBar(R.color.transparent)
(window.decorView.findViewById(Window.ID_ANDROID_CONTENT) as FrameLayout).foreground = null
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
if (controller != null) {
controller.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val w = window // in Activity's onCreate() for instance
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
w.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
)
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
Glide.with(this)
.load(R.drawable.my_splash_logo)
.into(R.id.splash_logo_imageview)
...
...
...
}
}
活动_启动. xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="@dimen/match_constraint"
android:layout_height="@dimen/match_constraint">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/splash_screen_logo_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/splash_logo_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<include layout="@layout/my_loading_view" />
<Space
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="center_horizontal|bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>
我还应用了png的精确像素,如.apply(RequestOptions().override(1110, 1144).centerCrop())
或.centerInside()
或.circleCrop()
或.fitCenter()
。
当我ONLY在没有任何Glide代码行的ImageView中使用android:src="@drawable/my_splash_logo"
时,我会看到大小差异。如果在没有任何Glide代码行的ImageView中使用此行,我会看到大小小于使用Glide代码行时的结果大小。
我错过了什么?
1条答案
按热度按时间idv4meu81#
不看图片资源很难说。我猜当你把它设置为
android:src="@drawable/my_splash_logo"
时,它只是从与你的屏幕密度相对应的图片资源文件夹中抓取图片,例如xhdpi
。但是当你使用Glide加载它时,它可能会抓取最大的可用图片,例如,从xxxhdpi
文件夹,并调整其大小,以匹配可用空间。因此,在情况下与滑翔图像可能看起来更大。