Моя цель — показать фоновое изображение SVG, заполняющее всю ширину экрана, в виде ConstraintLayout
. На это фоновое изображение наложен Button
, поэтому вы можете увидеть его на макете ниже:
Фоновое изображение — это то, которое содержит звезды. Его начальная и конечная стороны будут ограничены корнем GroupView
, чтобы он полностью заполнил ширину экрана.
Проблема заключается в следующем: независимо от того, привязываю ли я нижнюю сторону к нижней стороне экрана или нет, фоновое изображение выглядит искаженным, как показано ниже:
Вот код, который я написал:
<ImageView
android:id = "@+id/imageView16"
android:layout_width = "0dp"
android:layout_height = "wrap_content"
android:orientation = "horizontal"
android:background = "@drawable/ic_background_stars"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintTop_toBottomOf = "@id/linearLayout4" // "linearLayout4" is just a widget shown above, it's not an important element for this StackOverflow question
/>
<Button
android:id = "@+id/button_home_share"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_margin = "24dp"
android:background = "@color/colorRoyalRedLight"
android:text = "TextView"
android:textAllCaps = "false"
android:textColor = "@color/white"
app:layout_constraintStart_toStartOf = "@+id/imageView16"
app:layout_constraintEnd_toEndOf = "@+id/imageView16"
app:layout_constraintTop_toTopOf = "@+id/imageView16"
app:layout_constraintBottom_toBottomOf = "@+id/imageView16"
/>
Как я мог использовать свое изображение SVG в качестве фонового изображения, которое отображалось бы без каких-либо искажений, заполняя всю ширину экрана? Высота, конечно, может изменяться (для сохранения хороших пропорций), но не должна быть короче (по оси Y и по оси X) кнопки.
Для настройки ImageView
попробуйте android:scaleType = "centerCrop"
. См. ImageView.ScaleType.
CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view. From XML, use this syntax: android:scaleType = "centerCrop".
Ответы здесь заставляют ваши: stackoverflow.com/questions/55562638/… и взаимно