动画listView里面的片段

时间:2013-09-13 06:48:05

标签: android android-fragments android-animation

我有一个应用程序,在片段ok

中显示listView

现在我需要为列表视图设置动画

但动画

  

动画()

无效

这里是代码,

public class PhoneMainView extends SherlockFragment{

ListView listView ;
TranslateAnimation mAnimation;


//testeo
private Button btnNewEmpresa;

RelativeLayout lLayoutFrgValidate;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){


    Log.d("mensa", "ONCREATE");

    lLayoutFrgValidate=(RelativeLayout) inflater.inflate(R.layout.activity_main, container, false);

          btnNewEmpresa=(Button) lLayoutFrgValidate.findViewById(R.id.button_anima);

          btnNewEmpresa.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                  Log.d("mensa", "sikas");
                  animate();
            }
        });

    return lLayoutFrgValidate; 
}

public void onActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);

    Log.d("mensa", "onActivityCreated");

    listView = (ListView) getView().findViewById(R.id.listViewCats);

    String[] values = new String[] { "C0","C1","C2","C3",  "C4",  "C5", "C6","C7" 
                                    };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, values);

          listView.setAdapter(adapter); 
}

public void animate() {
    mAnimation = new TranslateAnimation(0, 0, 0, 599);
    mAnimation.setDuration(10000);
    mAnimation.setFillAfter(true);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    listView.setAnimation(mAnimation);
}

  }

1 个答案:

答案 0 :(得分:3)

你需要开始动画。

listView.startAnimation(mAnimation); // Use this