Skip to content

Commit 93f5555

Browse files
committed
Show what layout animations look like
1 parent 66a0fe2 commit 93f5555

7 files changed

Lines changed: 32 additions & 2 deletions

File tree

app/src/main/java/com/commit451/adapterlayout/sample/MainActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.commit451.adapterlayout.sample;
22

3+
import android.animation.LayoutTransition;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.support.design.widget.Snackbar;
67
import android.support.v7.app.AppCompatActivity;
78
import android.support.v7.widget.Toolbar;
89
import android.view.MenuItem;
910
import android.view.ViewGroup;
11+
import android.widget.CheckBox;
12+
import android.widget.CompoundButton;
1013

1114
import com.commit451.adapterlayout.AdapterLinearLayout;
1215

@@ -23,6 +26,8 @@ public class MainActivity extends AppCompatActivity {
2326
@Bind(R.id.adapter_layout)
2427
AdapterLinearLayout mAdapterLinearLayout;
2528
CheeseAdapter mAdapter;
29+
@Bind(R.id.animate_layout_changes)
30+
CheckBox mCheckboxAnimateLayoutChanges;
2631

2732
@OnClick(R.id.add_cheese)
2833
void onAddCheeseClicked() {
@@ -84,5 +89,17 @@ public boolean onMenuItemClick(MenuItem item) {
8489
});
8590
mAdapter = new CheeseAdapter(mListener);
8691
mAdapterLinearLayout.setAdapter(mAdapter);
92+
93+
mCheckboxAnimateLayoutChanges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
94+
@Override
95+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
96+
if (isChecked) {
97+
LayoutTransition lt = new LayoutTransition();
98+
mAdapterLinearLayout.setLayoutTransition(lt);
99+
} else {
100+
mAdapterLinearLayout.setLayoutTransition(null);
101+
}
102+
}
103+
});
87104
}
88105
}

app/src/main/res/layout/activity_main.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
android:id="@+id/root"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6-
android:orientation="vertical">
6+
android:orientation="vertical"
7+
android:clipChildren="false">
78

89
<android.support.v7.widget.Toolbar
910
android:id="@+id/toolbar"
1011
android:layout_width="match_parent"
1112
android:layout_height="?attr/actionBarSize"
1213
android:background="?attr/colorPrimary" />
1314

15+
<!--
16+
Only need to set clip children to false if you want
17+
to animate layout changes
18+
-->
1419
<ScrollView
1520
android:layout_width="match_parent"
16-
android:layout_height="wrap_content">
21+
android:layout_height="wrap_content"
22+
android:clipChildren="false">
1723

1824
<LinearLayout
1925
android:layout_width="match_parent"
@@ -24,6 +30,7 @@
2430
android:id="@+id/adapter_layout"
2531
android:layout_width="wrap_content"
2632
android:layout_height="wrap_content"
33+
android:animateLayoutChanges="true"
2734
android:orientation="vertical" />
2835

2936
<com.wefika.flowlayout.FlowLayout
@@ -66,6 +73,12 @@
6673
android:layout_height="wrap_content"
6774
android:text="New Adapter" />
6875

76+
<CheckBox
77+
android:id="@+id/animate_layout_changes"
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:text="Animate Layout Changes"/>
81+
6982
</com.wefika.flowlayout.FlowLayout>
7083
</LinearLayout>
7184
</ScrollView>
-2.45 KB
Loading
-1.51 KB
Loading
-3.48 KB
Loading
-5.59 KB
Loading
-7.43 KB
Loading

0 commit comments

Comments
 (0)