ScaleX/Y in android sabotages the layout arrangement

Viewed 73

I'm trying to use the ScaleX and Y in my layout, but using it doesn't really change the view size but affects the layout measures. for example if I use ScaleX and ScaleY on a switch button and then sets the parent size to match_parent it crops the scaled view to the original size.


screenshots:

not scaled:

unscaled

1.5 scale:

enter image description here

As you can see, the wrap_content property of the wrapper LinearLayout crops the Switch


Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00ffdf"
        >
        
        <Switch
            android:id="@+id/switch2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello"
            android:scaleY="1" ("1.5" in the second screenshot)
            android:scaleX="1" ("1.5" in the second screenshot)
            android:switchPadding="10sp"
            />
        
    </LinearLayout>
</LinearLayout>

Similar problem occurs when using Constraints in ConstraintLayout f.e,the constraints are measured from the original view borders and not from the scaled one.


How can I fix it and tell the layout to work with the scaled dimensions?

0 Answers
Related