Android圆形显示动画不起作用

问题描述 投票:0回答:1
sharedActivity.kt.. main file    

package com.example.animation_android

    import android.animation.Animator
    import android.animation.AnimatorListenerAdapter
    import android.os.Bundle
    import android.support.v7.app.AppCompatActivity
    import android.view.View
    import android.view.ViewAnimationUtils
    import android.widget.Button
    import android.widget.RelativeLayout
    import android.widget.TextView

    class SharedActivity : AppCompatActivity() {

        private var revealDemo : RelativeLayout? = null

        override fun onCreate(savedInstanceState: Bundle?) {

    //to enable transition
      //      window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)

            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_shared_element)

            initPage()
        }
    //after doing back
        override fun onSupportNavigateUp(): Boolean {
            finishAfterTransition()
            return true
        }

        private fun initPage() {

            // Toolbar declaration
            supportActionBar?.setDisplayHomeAsUpEnabled(true)
            supportActionBar?.title = "Shared element Transition"

            revealDemo = findViewById(R.id.click_reveal)
            revealDemo?.setOnClickListener {
                makeCircularRevealAnimation(revealDemo!!)
            }

            val btnexit:Button = findViewById(R.id.exit_button)
            btnexit.setOnClickListener{
                finishAfterTransition()


            }
        }
    **here function block for Reveal animation**
        private fun makeCircularRevealAnimation(revealDemo: RelativeLayout) {

            val textDesc : TextView = findViewById(R.id.textDesc)

            val centerx = (revealDemo?.left + revealDemo?.right ) / 2
            val centery = (revealDemo?.top + revealDemo?.bottom ) / 2

            val radius : Float = Math.max(textDesc.width,textDesc.height) * 2.0F

            if(textDesc.visibility == View.INVISIBLE) {
                textDesc.visibility == View.VISIBLE
                textDesc.setText(R.string.description)

                ViewAnimationUtils.createCircularReveal(textDesc,centerx,centery,0F,radius).start()
            }
            else
            {
                val reveal : Animator = ViewAnimationUtils.createCircularReveal(textDesc,centerx,centery,radius,0F)
                reveal.addListener(object : AnimatorListenerAdapter()
                {
                    override fun onAnimationEnd(animation: Animator?) {
                        textDesc.visibility == View.VISIBLE
                    }
                }
                )
                reveal.start()

            }

        }
    }

Activity_shared_element.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:color/white"
    android:gravity="center_horizontal"
    android:padding="10dp"
    android:id="@+id/click_reveal">   <- layout on clicklistner defined

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/textDesc"
        android:padding="20dp"
        android:background="#f0ce11"
        android:gravity="center"
        android:visibility="invisible"
        android:elevation="4dp"/>


    <TextView
        android:id="@+id/activity_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rahul Katiyar"
        android:textColor="@android:color/darker_gray"
        android:textSize="30sp"
        android:transitionName="smartherd_shared"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/LinearLayout"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/activity_title">

        <!-- same transition Name -->

    <ImageView
        android:id="@+id/logo_reveal"
        android:layout_width="200dp"
        android:layout_height="175dp"
        android:transitionName="logo_shared"
        android:src="@drawable/mylogo"/>

    <ImageView
        android:id="@+id/img_reveal"
        android:layout_width="200dp"
        android:layout_height="175dp"
        android:transitionName="pic_shared"
        android:src="@drawable/myimage"/>

</LinearLayout>

    <Button
        android:id="@+id/exit_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="EXIT [Back Press]"
        android:layout_below="@+id/textView2"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="51dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/description"
        android:id="@+id/textView2"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"/>


</RelativeLayout>

所有代码和xml文件在Android Studio中都是正确的。但我无法启动通告显示过渡。所有细节都已在上面添加。还为活动定义功能私人乐趣makeCircularRevealAnimation(revealDemo:RelativeLayout)但对我不起作用。大家好,让我知道代码中缺少什么?

android kotlin material-design swrevealviewcontroller
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.