Reputation: 37
I have a feeling I'm going to be using this site a lot. As I move through this project I feel like I'm using you guys as a crutch, but good lord are you great at helping me. Here's my current issue:
My app has TabSwype navigation and fragments. The main fragment has an ImageView and a Button, You press the button and a Tween animation takes place. Simple right?
I've got it all in place to where it won't crash on me, and the tween does NOTHING. SO frustrating. Here's my code.
Main Fragment:
package edu.wmich.lab4_jjohns1119;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation;
public class MainFragment extends Fragment {
//Declare widget objects
Button btnAnimate;
ImageView imgTween;
Animation tweenAnimation;
//create view
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Inflater
View rootView = inflater.inflate(R.layout.fragment_main, container,false);
//Button
btnAnimate = (Button)rootView.findViewById(R.id.btnAnimate);
//Image
imgTween = (ImageView)rootView.findViewById(R.id.imgTween);
//Animation Resource
tweenAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.tween1);
//Button listener for animation
btnAnimate.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//animate image
imgTween.startAnimation(tweenAnimation);
}
});
//Return view
return rootView;
}
}
fragment_main.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" >
<Button
android:id="@+id/btnAnimate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp"
android:text="@string/button_text_animate" />
<ImageView
android:id="@+id/imgTween"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="39dp"
android:src="@drawable/android_logo" />
</RelativeLayout>
And my Tween.XML:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http//schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-45"
android:duration="400"
/>
Upvotes: 0
Views: 295
Reputation: 4840
You don't have your animation within a <set>
. You also need to provide an interpolator for your animation. Try changing your xml to this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator" >
<rotate
android:fromDegrees="0"
android:toDegrees="-45"
android:duration="400" />
</set>
Upvotes: 2