Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to display the animation effects of shared elements by Android

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "Android how to show the animation effects of shared elements", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Android how to display shared element animation effects" article.

Bug description

Design students want to make a click on the picture in the item,item to move to the location of the picture on the new page. You can do it by thinking about sharing elements.

Companion object {fun gotoDetail (context: Activity, dynamicId: String?, jumpComment: Boolean = false, shareElement: Boolean = false, imageView: ImageView? = null, nameView: TextView? = null, avatarView: ImageView? = null ) {LogUtils.w (shareElement) if (shareElement) {val intent = Intent (context, HomeDynamicDetailAcitvity::class.java) intent.putExtra ("dynamicId", dynamicId?: ") intent.putExtra (" jumpComment ", jumpComment) intent.putExtra (" shareElement ") ShareElement) val options = ActivityOptions .makeSceneTransitionAnimation (context, UtilPair.create (imageView, context.getString (R.string.dynamic_start_top_image)), UtilPair.create (avatarView, context.getString (R.string.dynamic_start_avatar)), UtilPair.create (nameView) Context.getString (R.string.dynamic_start_name)) / / val options = ActivityOptions.makeSceneTransitionAnimation (context, imageView, context.getString (R.string.dynamic_start_top_image)) / / start the new activity ActivityCompat.startActivity (context, intent) Options.toBundle ()} else {val params = HashMap () params ["dynamicId"] = dynamicId?: "params [" jumpComment "] = jumpComment context.toActivity (RoutePath.HOME_DYNAMIC_DETAIL, params)}

The result was written according to the document, but the effect was problematic. By putting the animation duration to 5x, it is found that it is not a normal translation animation, but first show a small picture and then gradually hide, and then gradually show the big picture of the new interface, the animation effect is obviously wrong.

Official document

To add screen transition animation between two Activity with a shared element:

\

Enable window content transition in the theme background.

Specify shared element transitions in the style.

Define transitions as XML resources.

Use the android:transitionName attribute to specify a common name for shared elements in both layouts.

Use the ActivityOptions.makeSceneTransitionAnimation () function.

Resolution proc

Baidu took a look to see if anyone had a similar problem, but it didn't. Also corresponding to the modification of the style theme and so on, it has no effect. Finally, after thinking about it, I built a new project and wrote a demo to test it. There is no problem with the above self-written code. Since there is no problem, there is a problem in the project code. The biggest difference with demo is that there are network requests and image loading operations in the project. If you've identified the uncertainty, give it a try.

SupportPostponeEnterTransition ()

SupportStartPostponedEnterTransition ()

A method of pausing, a method of starting animation, pausing the animation as soon as it is entered, starting the animation after the network request or image loading is finished, and solving the problem. Finally, it depends on the effect.

The above is about the content of this article on "how to display the animation effects of shared elements in Android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report