1

I created a custom view and am looking to scale the view AND it's bounds. Is this possible through the layout? Or maybe something I have to change in the CustomView's class?

When I used scaleX and scaleY in the layout files, the image can shrink, or grow, but ultimately the bounds stay where it's at.

Here is an example. To the left is the normal size and normal scale and to the right is the CustomView scaled by 0.5 in both the x and y axis. enter image description here

If it helps, the CustomView is made by a few ImageView in ConstraintLayout. I've tried just changing layout_width and layout_height to definite values but then only some views scale accordingly while others stay big.

EDIT:

Here is the xml file for the CustomView

<?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="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="40dp"
tools:ignore="ContentDescription">


<ImageView
    android:id="@+id/justiceTop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toTopOf="@+id/justiceBase"
    app:layout_constraintEnd_toEndOf="@+id/justiceBase"
    app:layout_constraintStart_toStartOf="@+id/justiceBase"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_justice_scale_top" />

<ImageView
    android:id="@+id/justiceBase"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/justiceTop"
    app:srcCompat="@drawable/ic_justice_scale_base" />

<ImageView
    android:id="@+id/justiceBeam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:rotation="0"
    app:layout_constraintBottom_toBottomOf="@+id/justiceTop"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/justiceTop"
    app:srcCompat="@drawable/ic_justice_scale_top_beam"
    tools:ignore="ContentDescription" />

<View
    android:id="@+id/leftWeightPivot"
    android:layout_width="1dp"
    android:layout_height="1dp"
    app:layout_constraintCircle="@id/justiceBeam"
    app:layout_constraintCircleAngle="260"
    app:layout_constraintCircleRadius="70dp"
    tools:ignore="MissingConstraints" />

<View
    android:id="@+id/rightWeightPivot"
    android:layout_width="1dp"
    android:layout_height="1dp"
    app:layout_constraintCircle="@id/justiceBeam"
    app:layout_constraintCircleAngle="100"
    app:layout_constraintCircleRadius="70dp"
    tools:ignore="MissingConstraints" />

<ImageView
    android:id="@+id/justiceWeightLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="@id/leftWeightPivot"
    app:layout_constraintStart_toStartOf="@id/leftWeightPivot"
    app:layout_constraintTop_toBottomOf="@id/leftWeightPivot"
    app:srcCompat="@drawable/ic_justice_scale_weight" />

<ImageView
    android:id="@+id/justiceWeightRight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="@id/rightWeightPivot"
    app:layout_constraintStart_toStartOf="@id/rightWeightPivot"
    app:layout_constraintTop_toBottomOf="@id/rightWeightPivot"
    app:srcCompat="@drawable/ic_justice_scale_weight" />

And here's what happens if I set the layout_width and layout_height to 130dp

enter image description here

Rayaarito
  • 400
  • 4
  • 21

0 Answers0