DefaultLayoutAnimations should use GridLayout instead.
The 2-LinearLayout system the demo used to have had its quirks, but was just plain awful once it ran on a smaller screen. The new GridLayout makes for a much better experience. Change-Id: Ie3fd65e125c82da8b0079f61bd91bf844dea9b03
This commit is contained in:
@@ -24,18 +24,11 @@
|
||||
android:text="Add Button"
|
||||
android:id="@+id/addNewButton"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/horizontalContainer"
|
||||
android:animateLayoutChanges="true"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
<GridLayout
|
||||
android:columnCount="4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/verticalContainer"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/gridContainer"
|
||||
android:animateLayoutChanges="true"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -21,11 +21,11 @@ package com.example.android.apis.animation;
|
||||
import com.example.android.apis.R;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridLayout;
|
||||
|
||||
/**
|
||||
* This application demonstrates how to use the animateLayoutChanges tag in XML to automate
|
||||
@@ -35,36 +35,25 @@ public class LayoutAnimationsByDefault extends Activity {
|
||||
|
||||
private int numButtons = 1;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.layout_animations_by_default);
|
||||
|
||||
final ViewGroup horizontalContainer = (ViewGroup) findViewById(R.id.horizontalContainer);
|
||||
final ViewGroup verticalContainer = (ViewGroup) findViewById(R.id.verticalContainer);
|
||||
final GridLayout gridContainer = (GridLayout) findViewById(R.id.gridContainer);
|
||||
|
||||
Button addButton = (Button) findViewById(R.id.addNewButton);
|
||||
addButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Button newButton = new Button(LayoutAnimationsByDefault.this);
|
||||
newButton.setText("Click To Remove " + (numButtons++));
|
||||
newButton.setText(String.valueOf(numButtons++));
|
||||
newButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
horizontalContainer.removeView(v);
|
||||
gridContainer.removeView(v);
|
||||
}
|
||||
});
|
||||
horizontalContainer.addView(newButton, Math.min(1, horizontalContainer.getChildCount()));
|
||||
|
||||
newButton = new Button(LayoutAnimationsByDefault.this);
|
||||
newButton.setText("Click To Remove " + (numButtons++));
|
||||
newButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
verticalContainer.removeView(v);
|
||||
}
|
||||
});
|
||||
verticalContainer.addView(newButton, Math.min(1, verticalContainer.getChildCount()));
|
||||
gridContainer.addView(newButton, Math.min(1, gridContainer.getChildCount()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user