package th.zxq.com.quxianyundong;import android.app.SharedElementCallback;import android.content.Intent;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.view.ViewTreeObserver;import android.widget.ImageView;import java.util.List;import java.util.Map;/*** Created by Administrator on 2017/7/24.*/public class PicDetailActivity extends AppCompatActivity {private ImageView iv_push;private ViewPager viewpager;private int mCurrentPosition=-1;private ImageView currentiv;private boolean mIsReturning;private final SharedElementCallback mCallback = new SharedElementCallback() {@Overridepublic void onMapSharedElements(List names, Map sharedElements) {Log.e("callback","PicDetailActivity");if(mIsReturning&&mCurrentPosition!=Integer.parseInt(startpositon)){names.clear();names.add(currentiv.getTransitionName());sharedElements.clear();sharedElements.put(currentiv.getTransitionName(), currentiv);}}};private String startpositon;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_picdetail);postponeEnterTransition();startpositon = (String) getIntent().getExtras().get("transitionName");mCurrentPosition=Integer.parseInt(startpositon);setEnterSharedElementCallback(mCallback);iv_push= (ImageView) findViewById(R.id.iv_push);viewpager = (ViewPager) findViewById(R.id.viewpager);viewpager.setAdapter(new Myadapter());viewpager.setCurrentItem(Integer.parseInt(startpositon));//iv_push.setTransitionName(transitionName);//iv_push.setBackgroundResource(MyAnimationActivity.list[Integer.parseInt(transitionName)]);viewpager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){@Overridepublic void onPageSelected(int position) {mCurrentPosition = position;}});}public class Myadapter extends PagerAdapter{private View view;public Myadapter(){}@Overridepublic int getCount() {return MyAnimationActivity.list.length;}@Overridepublic boolean isViewFromObject(View view, Object object) {return view==object;}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView((ImageView) object);//super.destroyItem(container, position, object);}@Overridepublic Object instantiateItem(ViewGroup container, int position) {//实例化Item// TODO Auto-generated method stubview =LayoutInflater.from(PicDetailActivity.this).inflate(R.layout.item_detailpagerview, null);final ImageView iv_pager= (ImageView) view.findViewById(R.id.iv_pager);iv_pager.setTransitionName(position+"");iv_pager.setBackgroundResource(MyAnimationActivity.list[Integer.parseInt(iv_pager.getTransitionName())]);iv_pager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {@Overridepublic boolean onPreDraw() {iv_pager.getViewTreeObserver().removeOnPreDrawListener(this);startPostponedEnterTransition();return true;}});ViewGroup vg= (ViewGroup) iv_pager.getParent();vg.removeView(iv_pager);container.addView(iv_pager);return iv_pager;}@Overridepublic void setPrimaryItem(ViewGroup container, int position, Object object) {super.setPrimaryItem(container, position, object);currentiv= (ImageView) object;}}@Overridepublic void finishAfterTransition() {mIsReturning = true;Intent data = http://www.kingceram.com/post/new Intent();data.putExtra("currentItem",mCurrentPosition);setResult(RESULT_OK, data);super.finishAfterTransition();}}
【Android开发 之 共享元素】上面代码中的k是在退出和进入的时候都会调用一次 。
- android n彩蛋小米,小米小爱同学3大彩蛋公布 可一句话搞定N件事
- 分享招聘管理小程序开发制作步骤_招聘小程序怎么制作
- 如何开发一个求职招聘小程序?详细步骤解析与教程
- 用 Python 开发一个【视频营销号】生成器
- SAP PO 开发七 接口开发技术概念与名词术语解释
- 【从零开始游戏开发】静态资源优化 | 全面总结 |建议收藏
- 2023佛山敏捷之旅暨DevOps Meetup精彩回顾
- 如何借用敏捷实现IT对数字化转型支持 | 2023佛山敏捷之旅成功举办
- 7 java并发编程实战 并发工具JUC之CountDownLatch
- 受电弓升不起原因之两节机车受电弓均升不起