Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.apis.view;
     18 
     19 import android.app.ListActivity;
     20 import android.os.Bundle;
     21 import android.view.animation.AlphaAnimation;
     22 import android.view.animation.Animation;
     23 import android.view.animation.AnimationSet;
     24 import android.view.animation.LayoutAnimationController;
     25 import android.view.animation.TranslateAnimation;
     26 import android.widget.ArrayAdapter;
     27 import android.widget.ListView;
     28 
     29 public class LayoutAnimation2 extends ListActivity {
     30     @Override
     31     public void onCreate(Bundle savedInstanceState) {
     32         super.onCreate(savedInstanceState);
     33 
     34         setListAdapter(new ArrayAdapter<String>(this,
     35                 android.R.layout.simple_list_item_1, mStrings));
     36 
     37         AnimationSet set = new AnimationSet(true);
     38 
     39         Animation animation = new AlphaAnimation(0.0f, 1.0f);
     40         animation.setDuration(50);
     41         set.addAnimation(animation);
     42 
     43         animation = new TranslateAnimation(
     44             Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
     45             Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
     46         );
     47         animation.setDuration(100);
     48         set.addAnimation(animation);
     49 
     50         LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
     51         ListView listView = getListView();
     52         listView.setLayoutAnimation(controller);
     53     }
     54 
     55     private String[] mStrings = {
     56         "Bordeaux",
     57         "Lyon",
     58         "Marseille",
     59         "Nancy",
     60         "Paris",
     61         "Toulouse",
     62         "Strasbourg"
     63     };
     64 }
     65