ImageView 내부의 배경 회전 (Android Studio-Java)

Sep 26 2020

Android 애플리케이션을 개발하려고합니다. 그러나 문제에 직면하여 화려한 사각형 배경을 360도 회전시키고 싶습니다 . 애니메이션 효과가 될 것입니다. 계속 회전합니다. 가능합니까?

view.animate (). rotate () 시도했지만 물론 imageview를 회전시킵니다. imageview에서 배경 드로어 블을 회전하고 싶습니다.

내 목표

활동 레이아웃

<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="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/border"
    android:contentDescription="@string/todo"
    android:cropToPadding="true"
    android:padding="10dp"
    android:scaleType="centerCrop"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent />
</androidx.constraintlayout.widget.ConstraintLayout>

배경 (@ drawable / border)

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:angle="270"
    android:endColor="@color/colorYellowGreen"
    android:type="linear"
    android:centerColor="@color/colorBlue"
    android:startColor="@color/colorPink" />

<corners android:radius="5dp" />

답변

SnefruClone Oct 10 2020 at 08:10

애니메이션 목록에서 회전 태그를 사용했습니다.

<?xml version="1.0" encoding="utf-8"?>
<animation-list 
xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:duration="3000">
    <rotate
        android:fromDegrees="90"
        android:toDegrees="180"
        android:drawable="@drawable/border"
        android:pivotY="50%"
        android:pivotX="50%"/>
</item>
<item
    android:duration="3000">
    <rotate
        android:fromDegrees="180"
        android:toDegrees="270"
        android:drawable="@drawable/border"
        android:pivotY="50%"
        android:pivotX="50%"/>
</item>
<item
    android:duration="3000">
    <rotate
        android:fromDegrees="270"
        android:toDegrees="360"
        android:drawable="@drawable/border"
        android:pivotY="50%"
        android:pivotX="50%"/>
</item>
<item
    android:duration="3000">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="90"
        android:drawable="@drawable/border"
        android:pivotY="50%"
        android:pivotX="50%"/>
</item>

</animation-list>

위의 코드는 선택 사항 일 수 있지만 이것은 연속 회전에 가장 중요한 부분입니다.

AnimationDrawable animationDrawable =
(AnimationDrawable) mQRImage.getBackground();
animationDrawable.setExitFadeDuration(3000);
animationDrawable.start();