Can I scale a View in Android? Can I scale a View in Android? android android

Can I scale a View in Android?


You need API 11 or above to scale a view. Here is how:

float scalingFactor = 0.5f; // scale down to half the sizeview.setScaleX(scalingFactor);view.setScaleY(scalingFactor);


In your XML

android:scaleX="0.5"android:scaleY="0.5"


For scale, I resize the width and height of the view to make it affect the area and position another view.
If you don't want it affect the area and position, use answer of @Gadzair and @Taiti

private void resize(View view, float scaleX, float scaleY) {    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();    layoutParams.width = (int) (view.getWidth() * scaleX);    layoutParams.height = (int) (view.getHeight() * scaleY);    view.setLayoutParams(layoutParams);}

Example using

resize(view, 0.5f, 0.8f);

Result
Example

Demo