I installed my app on a device for the first time. It worked great on the emulator but it now has this white padding on the edges which affects the locations of the transparent buttons (See screenshot). I am wondering if there is a way to force the whole image to take up the full screen and remove the white on the sides. Please let me know your best solutions.
Thanks.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".firstroom">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/firstroom" />
</androidx.constraintlayout.widget.ConstraintLayout>
3
Answers
You can use
android:scaleType="centerCrop"
orandroid:scaleType="fitXY"
in your ImageView.I woulld also recommend you to go through this link: https://thoughtbot.com/blog/android-imageview-scaletype-a-visual-guide
You can use the "scaleType" attribute in the tag to ImageView
or
There are some other other types also . Shown in image below
You have to use the attribute
android:scaleType
.If you want to keep the aspect ratio unchanged, then you have to use
android:scaleType="centerCrop"
, this will center your image to the imageview and scale it keeping the aspect ratio. So it might crop either some portions of width or height if required.If you do not want to keep the aspect ratio, then you have to use
android:scaleType="fitXY"
, this will scale both height and width to fill your image to the imageview. As a result your image might be stretched horizontally or vertically.For more info, see official doc.