我的代码存在问题,当我尝试运行第一个动画时,包括将图像大小调整为大约50%,同时使其成为一个圆圈,然后是另一个具有波纹显示效果的活动的共享偏好,这一切都是一种情况同时发生,共享元素大多不起作用。
我的第二个问题是,当我使用onDestroy按钮时,它会跳回并且不会将图像恢复为原始大小。
这里是我的代码任何帮助将不胜感激...
MainActivity.java
public class MainActivity extends AppCompatActivity {
ImageView Lemon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Lemon = (ImageView) findViewById(R.id.square);
Lemon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//holds refrence to circle Transform.
//this is to make it a circle
Picasso.with(getApplicationContext())
.load(R.drawable.birds)//the image
.transform(new CircleTransform())
.resize(128, 128)
.centerCrop()
.into(Lemon);//and what image view to put it in
Animation a = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.reduce);
Lemon.startAnimation(a);
//resize
Animation a = AnimationUtils.loadAnimation(this, R.anim.reduce);
Lemon.startAnimation(a);
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
Lemon.clearAnimation();
}
}
sample.java
public class sample extends Activity{
ImageView Big;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_b);
Big = (ImageView) findViewById(R.id.bigBird);
if (savedInstanceState == null) {
Big.setVisibility(View.INVISIBLE);
ViewTreeObserver viewTreeObserver = Big.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
circularRevealActivity();
Big.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
}
}
private void circularRevealActivity() {
int cx = Big.getWidth() / 2;
int cy = Big.getHeight() / 2;
float finalRadius = Math.max(Big.getWidth(), Big.getHeight());
// create the animator for this view (the start radius is zero)
Animator circularReveal = ViewAnimationUtils.createCircularReveal(Big, cx, cy, 0, finalRadius);
circularReveal.setDuration(1000);
// make the view visible and start the animation
Big.setVisibility(View.VISIBLE);
circularReveal.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
Big.clearAnimation();
}
}
activitymain.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nazim.reducesharedelement.MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:src="@drawable/birds"
android:id="@+id/square"
android:onClick="animation"
android:fillAfter="true"
android:fillEnabled="true"
android:transitionName="@string/sharedelement"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
sample_b.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/birds"
android:layout_gravity="top|center_horizontal"
android:transitionName="@string/sharedelement"
android:id="@+id/bigBird"/>
</LinearLayout>
编译
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
我为糟糕的格式化而道歉,但我努力工作。请简单解释一下。任何给予的帮助将不胜感激。