[英]How to create background images for multiple screen sizes and densities
我目前正在开发一个可以在不同智能手机上运行的应用程序,我们的背景图像将出现在应用程序的所有活动中。
目前所有的父布局都是ConstraintLayout,背景图片设置在一个覆盖整个屏幕的ImageView中。 但是,在某些屏幕尺寸上,在 fitCenter 上设置fitCenter
根本不起作用,因为:
我知道我可以运行不同的 scaleType,但这可能会破坏背景图像的原始纵横比。
有这方面的设计规则吗?
我看过 ,但我只从 Android Dev 的网站上找到了这个。 它记录了大部分屏幕尺寸,但没有记录纵横比。
go 关于这个的最佳方法是什么?
我们是否应该为每个屏幕密度中的最大尺寸制作一个,并只希望相同屏幕密度范围内的相同屏幕正确缩放它? 还是每个维度只有一个? 还是每个纵横比只有一个?
我通常使用 ConstraintLayout 来保持图像比例
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.5"
android:orientation="vertical"/>
<ImageView
android:id="@+id/img_poster"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintDimensionRatio="3:4"
app:layout_constraintEnd_toEndOf="@id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
只要图像比例为3:4,它就不会裁剪实际图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.