1 /* 2 * Copyright (C) 2010 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.animation; 18 19 // Need the following import to get access to the app resources, since this 20 // class is in a sub-package. 21 import com.example.android.apis.R; 22 23 import android.view.View; 24 25 import android.app.Activity; 26 import android.os.Bundle; 27 import android.widget.Button; 28 import android.widget.GridLayout; 29 30 /** 31 * This application demonstrates how to use the animateLayoutChanges tag in XML to automate 32 * transition animations as items are removed from or added to a container. 33 */ 34 public class LayoutAnimationsByDefault extends Activity { 35 36 private int numButtons = 1; 37 38 @Override 39 public void onCreate(Bundle savedInstanceState) { 40 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.layout_animations_by_default); 43 44 final GridLayout gridContainer = (GridLayout) findViewById(R.id.gridContainer); 45 46 Button addButton = (Button) findViewById(R.id.addNewButton); 47 addButton.setOnClickListener(new View.OnClickListener() { 48 public void onClick(View v) { 49 Button newButton = new Button(LayoutAnimationsByDefault.this); 50 newButton.setText(String.valueOf(numButtons++)); 51 newButton.setOnClickListener(new View.OnClickListener() { 52 public void onClick(View v) { 53 gridContainer.removeView(v); 54 } 55 }); 56 gridContainer.addView(newButton, Math.min(1, gridContainer.getChildCount())); 57 } 58 }); 59 } 60 61 }