-2

enter image description here

Please help me to do this , when i press the button the button size will be increase. I will give the screenshot. and i will also share some code of button

<Button
    android:id="@+id/sbi_button"
    style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="40dp"
    android:backgroundTint="#1B79E6"
    android:gravity="center"
    android:insetLeft="0dp"
    android:insetTop="0dp"
    android:insetRight="0dp"
    android:insetBottom="0dp"
    android:padding="12dp"
    app:icon="@drawable/ic_sbi"
    app:iconPadding="0dp"
    app:iconSize="17dp"
    app:iconTint="#FFFFFF"
    app:layout_constraintEnd_toStartOf="@id/axis_button"
    app:layout_constraintStart_toStartOf="@+id/guideline"
    app:layout_constraintTop_toBottomOf="@id/transfer_textView"
    app:rippleColor="@android:color/transparent"
    app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MyApp.Button.Circle"
    app:strokeWidth="0dp" />
Bruno
  • 3,872
  • 4
  • 20
  • 37
ArkaMondal
  • 35
  • 3
  • instead of screenshot give some code how do you handle this button – snachmsm Mar 30 '21 at 05:37
  • please see i will share the code – ArkaMondal Mar 30 '21 at 05:48
  • You might want to Change states with animation otherwise it will look weird . have a look at [This thread](https://stackoverflow.com/questions/37318133/animatedly-reduce-button-size-on-press-and-regain-its-size-on-release) .. Its doing opposite you will need to tweak it a bit . – ADM Mar 30 '21 at 06:42

1 Answers1

1

you can change size of Button (or any other View) using its LayoutParams

// obtaining reference to view, e.g. in Activity
Button b = findViewById(R.id.sbi_button); 

// setting new size
int newSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60,
            getResources().getDisplayMetrics()); // 60dp to px unit
b.getLayoutParams().width = newSize; // setting new width and height
b.getLayoutParams().height = newSize;
b.requestLayout(); // force remeasure and redraw, may not be needed
snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • You are right `requestLayout()` is not required here, you already changed the layout params . That will do it . Probably remove it its not a good practice to use `requestLayout` IMo – ADM Mar 30 '21 at 06:37
  • to be precise that won't do it. setting new `width` for `LayoutParams` is just attaching new value to some primitive variable stored in this class. framework is managing layout and remeasuring/refreshing oftenly, but not always, not regular. in some circumstances when framework won't need to be redrawn it won't force this `Button` to be remeasured and even with new size this `View` will stay same until some other action force remeasuring layout, which may take seconds. BUT I agree, in most cases `requestLayout()` won't be needed – snachmsm Mar 30 '21 at 06:49