There is an ImageButton button
<ImageButton
android:id="@+id/imageButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:onClick="onClickMenu"
app:srcCompat="@drawable/ic_baseline_point_white" />
I upload a 24dp-by-24dp image to it. I increase the width of the button to 48dp, the height remains the same, the picture is also stretched.
How can I make the size of the image in the button always remain unchanged?
Here is the original image of the image in the button
Set
android:layout_width="48dp"
android:scaleType="fitCenter"
Another option
<LinearLayout
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/text_title_01"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginStart="12dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:inputType="textMultiLine"
android:paddingTop="8dp"
android:text="@string/txt_title_01"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/imageButtonContainer"
android:layout_width="48dp"
android:layout_height="24dp"
android:onClick="onClickMenu">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:src="@drawable/ic_baseline_point_white" />
</RelativeLayout>
</LinearLayout>