0

I'm trying to animate state change of static drawable resources, using animated-selector by changing path data from one drawable to other, using bounce animations. However, the transition animation isn't triggerign at all.

This is the component:

<androidx.appcompat.widget.AppCompatImageButton
    android:id="@+id/camera_capture_button"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/ic_shutter"
    android:clickable="true"
    android:contentDescription="@string/camera__btn_capture"
    android:onClick="@{() -> viewModel.onCaptureClick()}"
    android:scaleType="fitCenter"
    app:layout_constraintTop_toTopOf="@id/bg_camera"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

This is the ic_shutter:

<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/state_pressed"
        android:drawable="@drawable/ic_shutter_pressed"
        android:state_pressed="true" />
    <item
        android:id="@+id/state_normal"
        android:drawable="@drawable/ic_shutter_normal"
        android:state_pressed="false" />

<transition
    android:fromId="@id/state_normal"
    android:toId="@id/state_pressed">
    <animation-list>
        <set>
            <item>
                <objectAnimator
                    android:duration="300"
                    android:interpolator="@android:interpolator/accelerate_decelerate"
                    android:propertyName="pathData"
                    android:valueFrom="M44,44.913m-34.089,0a34.089,34.089 0,1 1,68.177 0a34.089,34.089 0,1 1,-68.177 0"
                    android:valueTo="M44,44.913m-26.5,0a26.5,26.5 0,1 1,53 0a26.5,26.5 0,1 1,-53 0"
                    android:valueType="pathType" />
            </item>
        </set>
    </animation-list>
</transition>
</animated-selector>

These are respective drawable resources:

  1. ic_shutter_pressed:
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:aapt="http://schemas.android.com/aapt"
        android:width="88dp"
        android:height="89dp"
        android:viewportWidth="88"
        android:viewportHeight="89">
  

<path
      android:name="centerCircle"
      android:pathData="M44,44.913m-26.5,0a26.5,26.5 0,1 1,53 0a26.5,26.5 0,1 1,-53 0"
      android:strokeWidth="2"
      android:strokeColor="#ffffff">
    <aapt:attr name="android:fillColor">
      <gradient
          android:startX="26.54"
          android:startY="24.459"
          android:endX="61.46"
          android:endY="65.491"
          android:type="linear">
        <item android:offset="0" android:color="#FFD9DADB"/>
        <item android:offset="1" android:color="#FFFFFFFF"/>
      </gradient>
    </aapt:attr>
  </path>
</vector>
  1. ic_shutter_normal:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="88dp"
    android:height="89dp"
    android:viewportWidth="88"
    android:viewportHeight="89">
  <path
      android:name="centerCircle"
      android:pathData="M44,44.913m-34.089,0a34.089,34.089 0,1 1,68.177 0a34.089,34.089 0,1 1,-68.177 0"
      android:strokeWidth="2"
      android:strokeColor="#ffffff">
    <aapt:attr name="android:fillColor">
      <gradient
          android:startX="21.721"
          android:startY="18.815"
          android:endX="66.278"
          android:endY="71.169"
          android:type="linear">
        <item android:offset="0" android:color="#FFD9DADB"/>
        <item android:offset="1" android:color="#FFFFFFFF"/>
      </gradient>
    </aapt:attr>
  </path>
</vector>
arhon
  • 85
  • 1
  • 8
  • See [this question](https://stackoverflow.com/questions/38212831/how-to-set-imagebutton-property-of-appsrccompat-drawable-pic-programmaticall) and try that answer. could be the culprit. – Shark Jun 29 '23 at 11:50
  • I've checked out the link and possible solutions, such as using app:srcCompact, and setting the resource via code rather than the layout, however it doesn't make any difference and I don't see why it should. Resource is being set. If I remove transition animation, it works as a normal state list. What I'm having issue is the transitional animation itself. If I leave it as is, it would simply make the on click event the second resource invisibile, but it's set properly. – arhon Jun 30 '23 at 07:15

0 Answers0