我有一种感觉,我会经常使用这个网站。当我完成这个项目时,我觉得我很喜欢把你们当作拐杖,但是好主人,你们很擅长帮助我。这是我目前的问题:
我的应用有TabSwype导航和片段。主片段有一个ImageView和一个Button,你按下按钮就会发生一个Tween动画。简单吧?
我已经把这一切都安排到了它不会让我崩溃的地方,并且补间没有。太令人沮丧了。这是我的代码。
主要片段:
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>
我的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"
/>
答案 0 :(得分:2)
您没有<set>
内的动画。您还需要为动画提供插补器。尝试将xml更改为:
<?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>