├── .classpath
├── .project
├── AndroidManifest.xml
├── README.md
├── ic_launcher-web.png
├── images
└── demo.gif
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ ├── activity_main.xml
│ └── list_item.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── attrs.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── collapselayout
├── CollapseLayout.java
├── DemoList.java
├── ListViewDemo.java
└── MainActivity.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | CollapseLayout
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | CollapseLayout
2 | =================
3 | CollapseLayout can collapse/expand layout with smooth animation.
4 |
5 | Here is a gif showing the effect:
6 |
7 | 
8 |
9 |
10 | How to use
11 | ---------------
12 |
13 | ```xml
14 |
18 |
19 |
23 |
24 | .........
25 |
26 |
27 |
28 |
29 | ```
30 |
31 | ```java
32 | public void showEffect(View v) {
33 | int modeId = modeGroup.getCheckedRadioButtonId();
34 | switch (modeId) {
35 | case R.id.fixedTop:
36 | el.setCollapseMode(Mode.FIXED_START);
37 | break;
38 | case R.id.fixedBottom:
39 | el.setCollapseMode(Mode.FIXED_END);
40 | break;
41 | }
42 |
43 | int interpolatorId = interpolatorGroup.getCheckedRadioButtonId();
44 | switch (interpolatorId) {
45 | case R.id.linear:
46 | el.setInterpolator(linearInterpolator);
47 | break;
48 | case R.id.bounce:
49 | el.setInterpolator(bounceInterpolator);
50 | break;
51 | case R.id.accelerate:
52 | el.setInterpolator(accelerateDecelerateInterpolator);
53 | break;
54 | }
55 |
56 | int orientationId = orientationGroup.getCheckedRadioButtonId();
57 | switch (orientationId) {
58 | case R.id.vertical:
59 | el.setCollapseOrientation(Orientation.VERTICAL);
60 | break;
61 | case R.id.horizontal:
62 | el.setCollapseOrientation(Orientation.HORIZONTAL);
63 | break;
64 | }
65 |
66 | int state = el.getState();
67 | switch (state) {
68 | case CollapseLayout.STATE_OPEN:
69 | el.close();
70 | break;
71 | case CollapseLayout.STATE_CLOSE:
72 | el.open();
73 | break;
74 | }
75 | }
76 | ```
77 | ```xml
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | ```
94 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/ic_launcher-web.png
--------------------------------------------------------------------------------
/images/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/images/demo.gif
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ubdc/CollapseLayout/391927c924601b2e2b34cecd2e4bbb996956db83/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
10 |
16 |
17 |
22 |
23 |
29 |
30 |
35 |
36 |
37 |
42 |
43 |
49 |
50 |
55 |
56 |
61 |
62 |
63 |
68 |
69 |
75 |
76 |
81 |
82 |
83 |
84 |
90 |
91 |
95 |
96 |
100 |
101 |
107 |
108 |
114 |
115 |
121 |
122 |
123 |
124 |
130 |
131 |
137 |
138 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CollapseLayout
5 | Hello world!
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/example/collapselayout/CollapseLayout.java:
--------------------------------------------------------------------------------
1 | package com.example.collapselayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.animation.AccelerateDecelerateInterpolator;
7 | import android.view.animation.Interpolator;
8 | import android.widget.FrameLayout;
9 | import android.widget.Scroller;
10 |
11 | import com.example.expendlayout.R;
12 |
13 | public class CollapseLayout extends FrameLayout {
14 | private static final Interpolator DEFAULT_INTERPOLATOR = new AccelerateDecelerateInterpolator();
15 | private static final int DEFAULT_ANIM_TIME = 600;
16 | private State state;
17 | private Scroller mScroller;
18 | private int mMeasuredWidth;
19 | private int mMeasuredHeight;
20 | private Interpolator mInterpolator;
21 | private int mAnimTime = DEFAULT_ANIM_TIME;
22 | private CollapseMode mMode;
23 | private Orientation mCollapseOrientation;
24 | private CollapseListener mCollapseListener;
25 | private boolean mIsFirstLayout = true;
26 |
27 | private Runnable mVerticalAnim = new Runnable() {
28 |
29 | @Override
30 | public void run() {
31 | if (mScroller.computeScrollOffset()) {
32 | android.view.ViewGroup.LayoutParams lp = getLayoutParams();
33 | lp.width = mMeasuredWidth;
34 | lp.height = mScroller.getCurrY();
35 | setLayoutParams(lp);
36 | if (mMode == CollapseMode.PullOut) {
37 | scrollTo(0, mMeasuredHeight - mScroller.getCurrY());
38 | } else {
39 | scrollTo(0, 0);
40 | }
41 | post(this);
42 | } else {
43 | if (mCollapseListener != null) {
44 | if (mScroller.getCurrY() == 0) {
45 | mCollapseListener.onCloseComplete();
46 | } else {
47 | mCollapseListener.onOpenComplete();
48 | }
49 | }
50 | }
51 | }
52 | };
53 |
54 | private Runnable mHorizontalAnim = new Runnable() {
55 |
56 | @Override
57 | public void run() {
58 | if (mScroller.computeScrollOffset()) {
59 | android.view.ViewGroup.LayoutParams lp = getLayoutParams();
60 | lp.width = mScroller.getCurrX();
61 | lp.height = mMeasuredHeight;
62 | setLayoutParams(lp);
63 | if (mMode == CollapseMode.PullOut) {
64 | scrollTo(mMeasuredWidth - mScroller.getCurrX(), 0);
65 | } else {
66 | scrollTo(0, 0);
67 | }
68 | post(this);
69 | } else {
70 | if (mCollapseListener != null) {
71 | if (mScroller.getCurrX() == 0) {
72 | mCollapseListener.onCloseComplete();
73 | } else {
74 | mCollapseListener.onOpenComplete();
75 | }
76 | }
77 | }
78 | }
79 | };
80 |
81 | public CollapseLayout(Context context, AttributeSet attrs, int defStyle) {
82 | super(context, attrs, defStyle);
83 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapseLayout, defStyle, 0);
84 | setCollapseOrientation(Orientation.values()[a.getInt(R.styleable.CollapseLayout_collapseOrientation, 0)]);
85 | setCollapseMode(CollapseMode.values()[a.getInt(R.styleable.CollapseLayout_collapseMode, 0)]);
86 | state = State.values()[a.getInt(R.styleable.CollapseLayout_state, 0)];
87 | setAnimateDuration(a.getInt(R.styleable.CollapseLayout_collapseDuration, DEFAULT_ANIM_TIME));
88 | a.recycle();
89 | setInterpolator(DEFAULT_INTERPOLATOR);
90 | setFocusable(true);
91 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
92 | setWillNotDraw(false);
93 | }
94 |
95 | public CollapseLayout(Context context, AttributeSet attrs) {
96 | this(context, attrs, 0);
97 | }
98 |
99 | public CollapseLayout(Context context) {
100 | this(context, null);
101 | }
102 |
103 | @Override
104 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
105 | if (mIsFirstLayout) {
106 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
107 | mMeasuredWidth = getMeasuredWidth();
108 | mMeasuredHeight = getMeasuredHeight();
109 | if (state == State.Close) {
110 | if (mCollapseOrientation == Orientation.Horizontal) {
111 | setMeasuredDimension(0, mMeasuredHeight);
112 | } else {
113 | setMeasuredDimension(mMeasuredWidth, 0);
114 | }
115 | }
116 | } else {
117 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
118 | }
119 | }
120 |
121 | @Override
122 | protected void onLayout(boolean changed, int left, int top, int right,
123 | int bottom) {
124 | super.onLayout(changed, left, top, right, bottom);
125 | }
126 |
127 | @Override
128 | protected void onDetachedFromWindow() {
129 | super.onDetachedFromWindow();
130 | if (!mScroller.isFinished()) {
131 | mScroller.abortAnimation();
132 | }
133 | mIsFirstLayout = true;
134 | }
135 |
136 | public void setInterpolator(Interpolator interpolator) {
137 | if (interpolator == null) {
138 | interpolator = DEFAULT_INTERPOLATOR;
139 | }
140 | if (interpolator == this.mInterpolator) {
141 | return;
142 | }
143 | this.mInterpolator = interpolator;
144 | mScroller = new Scroller(getContext(), interpolator);
145 | }
146 |
147 | public void setAnimateDuration(int duration) {
148 | if (duration <= 0) {
149 | duration = DEFAULT_ANIM_TIME;
150 | }
151 | mAnimTime = duration;
152 | }
153 |
154 | public void setCollapseMode(CollapseMode mode) {
155 | if (mode == null) {
156 | mode = CollapseMode.PullOut;
157 | }
158 | mMode = mode;
159 | }
160 |
161 | public void setCollapseOrientation(Orientation orientation) {
162 | if (orientation == null) {
163 | orientation = Orientation.Vertical;
164 | }
165 | mCollapseOrientation = orientation;
166 | }
167 |
168 | public void setCollapseListener(CollapseListener listener) {
169 | mCollapseListener = listener;
170 | }
171 |
172 | public State getState() {
173 | return state;
174 | }
175 |
176 | public void setState(State state) {
177 | if (state == null || this.state == state) {
178 | return;
179 | }
180 | this.state = state;
181 | mIsFirstLayout = true;
182 | requestLayout();
183 | }
184 |
185 | public void close() {
186 | mIsFirstLayout = false;
187 | switch (mCollapseOrientation) {
188 | case Vertical:
189 | verticalClose();
190 | break;
191 | case Horizontal:
192 | horizontalClose();
193 | break;
194 | }
195 | }
196 |
197 | private void verticalClose() {
198 | if (mMeasuredHeight > 0) {
199 | if (state == State.Close) {
200 | return;
201 | }
202 | state = State.Close;
203 | if (mScroller.isFinished()) {
204 | mScroller.startScroll(0, mMeasuredHeight, 0, -mMeasuredHeight, mAnimTime);
205 | } else {
206 | removeAnims();
207 | int currY = mScroller.getCurrY();
208 | mScroller.abortAnimation();
209 | mScroller.startScroll(0, currY, 0, -currY, mAnimTime * currY / mMeasuredHeight);
210 | }
211 | post(mVerticalAnim);
212 | }
213 | }
214 |
215 | private void horizontalClose() {
216 | if (mMeasuredWidth > 0) {
217 | if (state == State.Close) {
218 | return;
219 | }
220 | state = State.Close;
221 | if (mScroller.isFinished()) {
222 | mScroller.startScroll(mMeasuredWidth, 0, -mMeasuredWidth, 0, mAnimTime);
223 | } else {
224 | removeAnims();
225 | int currX = mScroller.getCurrX();
226 | mScroller.abortAnimation();
227 | mScroller.startScroll(currX, 0, -currX, 0, mAnimTime * currX / mMeasuredWidth);
228 | }
229 | post(mHorizontalAnim);
230 | }
231 | }
232 |
233 | public void open() {
234 | mIsFirstLayout = false;
235 | switch (mCollapseOrientation) {
236 | case Vertical:
237 | verticalOpen();
238 | break;
239 | case Horizontal:
240 | horizontalOpen();
241 | break;
242 | }
243 | }
244 |
245 | private void verticalOpen() {
246 | if (mMeasuredHeight > 0) {
247 | if (state == State.Open) {
248 | return;
249 | }
250 | state = State.Open;
251 | if (mScroller.isFinished()) {
252 | mScroller.startScroll(0, 0, 0, mMeasuredHeight, mAnimTime);
253 | } else {
254 | removeAnims();
255 | int currY = mScroller.getCurrY();
256 | mScroller.abortAnimation();
257 | mScroller.startScroll(0, currY, 0, mMeasuredHeight - currY, mAnimTime * (mMeasuredHeight - currY) / mMeasuredHeight);
258 | }
259 | post(mVerticalAnim);
260 | }
261 | }
262 |
263 | private void horizontalOpen() {
264 | if (mMeasuredWidth > 0) {
265 | if (state == State.Open) {
266 | return;
267 | }
268 | state = State.Open;
269 | if (mScroller.isFinished()) {
270 | mScroller.startScroll(0, 0, mMeasuredWidth, 0, mAnimTime);
271 | } else {
272 | removeAnims();
273 | int currX = mScroller.getCurrX();
274 | mScroller.abortAnimation();
275 | mScroller.startScroll(currX, 0, mMeasuredWidth - currX, 0, mAnimTime * (mMeasuredWidth - currX) / mMeasuredWidth);
276 | }
277 | post(mHorizontalAnim);
278 | }
279 | }
280 |
281 | private void removeAnims() {
282 | removeCallbacks(mHorizontalAnim);
283 | removeCallbacks(mVerticalAnim);
284 | }
285 |
286 | public enum CollapseMode {
287 | PullOut,
288 | LayDown;
289 | }
290 |
291 | public enum Orientation {
292 | Vertical,
293 | Horizontal;
294 | }
295 |
296 | public enum State {
297 | Open,
298 | Close;
299 | }
300 |
301 | public interface CollapseListener {
302 | void onOpenComplete();
303 | void onCloseComplete();
304 | }
305 | }
306 |
--------------------------------------------------------------------------------
/src/com/example/collapselayout/DemoList.java:
--------------------------------------------------------------------------------
1 | package com.example.collapselayout;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.ListView;
9 |
10 | public class DemoList extends ListActivity {
11 | String[] arr = {
12 | "basic",
13 | "ListView demo",
14 | };
15 |
16 | String[] clazz = {
17 | "com.example.collapselayout.MainActivity",
18 | "com.example.collapselayout.ListViewDemo",
19 | };
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | getListView().setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, arr));
25 | }
26 |
27 | @Override
28 | protected void onListItemClick(ListView l, View v, int position, long id) {
29 | try {
30 | Intent intent = new Intent(this, Class.forName(clazz[position]));
31 | startActivity(intent);
32 | } catch (ClassNotFoundException e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/example/collapselayout/ListViewDemo.java:
--------------------------------------------------------------------------------
1 | package com.example.collapselayout;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.app.ListActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.animation.BounceInterpolator;
11 | import android.widget.BaseAdapter;
12 | import android.widget.TextView;
13 |
14 | import com.example.collapselayout.CollapseLayout.State;
15 | import com.example.expendlayout.R;
16 |
17 | public class ListViewDemo extends ListActivity {
18 | List titles = new ArrayList<>();
19 | List contents = new ArrayList<>();
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | init();
25 | getListView().setAdapter(new MyAdapter());
26 | }
27 |
28 | private void init() {
29 | for (int i = 0; i < 100; i++) {
30 | titles.add("TITLE#" + i);
31 | }
32 | for (int i = 0; i < titles.size(); i++) {
33 | contents.add("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
34 | }
35 | }
36 |
37 | class MyAdapter extends BaseAdapter {
38 | boolean[] openState = new boolean[titles.size()];
39 |
40 | @Override
41 | public int getCount() {
42 | return titles.size();
43 | }
44 |
45 | @Override
46 | public Object getItem(int position) {
47 | return null;
48 | }
49 |
50 | @Override
51 | public long getItemId(int position) {
52 | return 0;
53 | }
54 |
55 | @Override
56 | public View getView(final int position, View convertView, ViewGroup parent) {
57 | Holder h = null;
58 | if (convertView == null) {
59 | convertView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
60 | h = new Holder();
61 | h.title = (TextView) convertView.findViewById(R.id.title);
62 | h.collapseContainer = (CollapseLayout) convertView.findViewById(R.id.collapseContainer);
63 | h.content = (TextView) convertView.findViewById(R.id.content);
64 | h.collapseContainer.setInterpolator(new BounceInterpolator());
65 | convertView.setTag(h);
66 | } else {
67 | h = (Holder) convertView.getTag();
68 | }
69 | h.title.setText(titles.get(position));
70 | final CollapseLayout collapseContianer = h.collapseContainer;
71 | if (openState[position]) {
72 | collapseContianer.setState(State.Open);
73 | } else {
74 | collapseContianer.setState(State.Close);
75 | }
76 | h.title.setOnClickListener(new View.OnClickListener() {
77 |
78 | @Override
79 | public void onClick(View v) {
80 | if (openState[position]) {
81 | collapseContianer.close();
82 | } else {
83 | collapseContianer.open();
84 | }
85 | openState[position] = !openState[position];
86 | }
87 | });
88 | h.content.setText(contents.get(position));
89 | return convertView;
90 | }
91 |
92 | class Holder {
93 | TextView title;
94 | CollapseLayout collapseContainer;
95 | TextView content;
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/com/example/collapselayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.collapselayout;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.animation.AccelerateDecelerateInterpolator;
7 | import android.view.animation.BounceInterpolator;
8 | import android.view.animation.LinearInterpolator;
9 | import android.widget.RadioGroup;
10 | import android.widget.Toast;
11 |
12 | import com.example.collapselayout.CollapseLayout.CollapseListener;
13 | import com.example.collapselayout.CollapseLayout.CollapseMode;
14 | import com.example.collapselayout.CollapseLayout.Orientation;
15 | import com.example.expendlayout.R;
16 |
17 | public class MainActivity extends Activity {
18 | LinearInterpolator linearInterpolator = new LinearInterpolator();
19 | BounceInterpolator bounceInterpolator = new BounceInterpolator();
20 | AccelerateDecelerateInterpolator accelerateDecelerateInterpolator = new AccelerateDecelerateInterpolator();
21 |
22 | Toast toast;
23 | CollapseLayout el;
24 | RadioGroup modeGroup;
25 | RadioGroup interpolatorGroup;
26 | RadioGroup orientationGroup;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 | toast = Toast.makeText(this, "", Toast.LENGTH_LONG);
33 | el = (CollapseLayout) findViewById(R.id.el);
34 | el.setCollapseListener(new CollapseListener() {
35 |
36 | @Override
37 | public void onOpenComplete() {
38 | showToast("onOpenComplete");
39 | }
40 |
41 | @Override
42 | public void onCloseComplete() {
43 | showToast("onCloseComplete");
44 | }
45 |
46 | });
47 | modeGroup = (RadioGroup) findViewById(R.id.mode);
48 | interpolatorGroup = (RadioGroup) findViewById(R.id.interpolator);
49 | orientationGroup = (RadioGroup) findViewById(R.id.orientation);
50 | }
51 |
52 | private void showToast(String msg) {
53 | toast.setText(msg);
54 | toast.show();
55 | }
56 |
57 | public void showEffect(View v) {
58 | int modeId = modeGroup.getCheckedRadioButtonId();
59 | switch (modeId) {
60 | case R.id.laydown:
61 | el.setCollapseMode(CollapseMode.LayDown);
62 | break;
63 | case R.id.pullout:
64 | el.setCollapseMode(CollapseMode.PullOut);
65 | break;
66 | }
67 |
68 | int interpolatorId = interpolatorGroup.getCheckedRadioButtonId();
69 | switch (interpolatorId) {
70 | case R.id.linear:
71 | el.setInterpolator(linearInterpolator);
72 | break;
73 | case R.id.bounce:
74 | el.setInterpolator(bounceInterpolator);
75 | break;
76 | case R.id.accelerate:
77 | el.setInterpolator(accelerateDecelerateInterpolator);
78 | break;
79 | }
80 |
81 | int orientationId = orientationGroup.getCheckedRadioButtonId();
82 | switch (orientationId) {
83 | case R.id.vertical:
84 | el.setCollapseOrientation(Orientation.Vertical);
85 | break;
86 | case R.id.horizontal:
87 | el.setCollapseOrientation(Orientation.Horizontal);
88 | break;
89 | }
90 |
91 | switch (el.getState()) {
92 | case Open:
93 | el.close();
94 | break;
95 | case Close:
96 | el.open();
97 | break;
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------