Adjust layouts of transition demos to improve fade-outs.

When a container's child count goes to zero, it may report a measurement size
of zero. This affects LayoutTransition's fading-out of target views
because they may get clipped out by a layout that got sized to 0 because it
thinks it has no children. The workaround is to tell the layout to size itself
either with some minimal size (in the case of the FixedGridLayout used by some
demos) or with match_parent in some cases to ensure that the layout always has
some nonzero size.

Change-Id: I908e64d4fb054928af277a021a328e94477c9c83
This commit is contained in:
Chet Haase
2011-02-15 09:46:28 -08:00
parent 15e889b5e0
commit 97ee3c3898
5 changed files with 13 additions and 10 deletions

View File

@@ -16,7 +16,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
>
<Button
android:layout_width="wrap_content"
@@ -27,7 +27,7 @@
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:id="@+id/horizontalContainer"
android:animateLayoutChanges="true"
/>

View File

@@ -16,13 +16,13 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:id="@+id/parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="wrap_content"

View File

@@ -64,9 +64,11 @@ public class FixedGridLayout extends ViewGroup {
final View child = getChildAt(index);
child.measure(cellWidthSpec, cellHeightSpec);
}
// Use the size our parents gave us
setMeasuredDimension(resolveSize(mCellWidth*count, widthMeasureSpec),
resolveSize(mCellHeight*count, heightMeasureSpec));
// Use the size our parents gave us, but default to a minimum size to avoid
// clipping transitioning children
int minCount = count > 3 ? count : 3;
setMeasuredDimension(resolveSize(mCellWidth * minCount, widthMeasureSpec),
resolveSize(mCellHeight * minCount, heightMeasureSpec));
}
@Override

View File

@@ -58,6 +58,7 @@ public class LayoutAnimations extends Activity {
setContentView(R.layout.layout_animations);
container = new FixedGridLayout(this);
container.setClipChildren(false);
((FixedGridLayout)container).setCellHeight(50);
((FixedGridLayout)container).setCellWidth(200);
final LayoutTransition transitioner = new LayoutTransition();
@@ -77,6 +78,7 @@ public class LayoutAnimations extends Activity {
ViewGroup parent = (ViewGroup) findViewById(R.id.parent);
parent.addView(container);
parent.setClipChildren(false);
Button addButton = (Button) findViewById(R.id.addNewButton);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

View File

@@ -53,10 +53,9 @@ public class LayoutAnimationsHideShow extends Activity {
final CheckBox hideGoneCB = (CheckBox) findViewById(R.id.hideGoneCB);
container = new FixedGridLayout(this);
((FixedGridLayout)container).setCellHeight(50);
((FixedGridLayout)container).setCellWidth(100);
container = new LinearLayout(this);
container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// Add a slew of buttons to the container. We won't add any more buttons at runtime, but
// will just show/hide the buttons we've already created