├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── icon_click_up.png
│ │ │ │ └── ic_expand_more.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── item_expandble_view.xml
│ │ │ │ ├── activity_model.xml
│ │ │ │ ├── item_expenable.xml
│ │ │ │ ├── item_expanble_querycar.xml
│ │ │ │ ├── item_expanble_caruniques.xml
│ │ │ │ ├── item_expanble_recycle.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── view
│ │ │ │ └── waitou
│ │ │ │ └── expandableview
│ │ │ │ ├── UniquesInfo.java
│ │ │ │ ├── QueryInfo.java
│ │ │ │ ├── ModelActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── ExpandableViewAdapter.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── view
│ │ │ └── waitou
│ │ │ └── expandableview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── view
│ │ └── waitou
│ │ └── expandableview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── explibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── attrs.xml
│ │ └── java
│ │ │ └── view
│ │ │ └── waitou
│ │ │ └── explibrary
│ │ │ └── ExpandableView.java
│ ├── test
│ │ └── java
│ │ │ └── view
│ │ │ └── waitou
│ │ │ └── explibrary
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── view
│ │ └── waitou
│ │ └── explibrary
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── Untitled20.gif
├── Untitled21.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/explibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':explibrary'
2 |
--------------------------------------------------------------------------------
/Untitled20.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/Untitled20.gif
--------------------------------------------------------------------------------
/Untitled21.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/Untitled21.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ExpandableView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon_click_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-xxhdpi/icon_click_up.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_expand_more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zguop/ExpandableView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_expand_more.png
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 02 10:31:45 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/view/waitou/expandableview/UniquesInfo.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | /**
4 | * Created by waitou on 16/9/24.
5 | * 物流二层车架列表
6 | */
7 | public class UniquesInfo {
8 |
9 | public boolean delivered;
10 |
11 | public String snap;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
7 | .externalNativeBuild
8 | *.apk
9 | *.ap_
10 | *.dex
11 | *.class
12 | bin/
13 | gen/
14 | # Log Files
15 | *.log
16 | .navigation/
17 | .idea/
18 | gradle.properties
19 | .bash_profile
20 | reports
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/view/waitou/expandableview/QueryInfo.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by waitou on 16/9/24.
7 | */
8 | public class QueryInfo {
9 |
10 | public List uniques;
11 |
12 | public String name;
13 |
14 | public boolean finished;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/explibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #E7E7E7
8 | #FF9003
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/explibrary/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/test/java/view/waitou/expandableview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/explibrary/src/test/java/view/waitou/explibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package view.waitou.explibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_expandble_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/waitou/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/explibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/waitou/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "view.waitou.expandableview"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation 'com.android.support:appcompat-v7:27.1.1'
23 | implementation 'com.android.support:recyclerview-v7:27.1.1'
24 | implementation project(':explibrary')
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_model.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
14 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_expenable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/view/waitou/expandableview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("view.waitou.expandableview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/explibrary/src/androidTest/java/view/waitou/explibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package view.waitou.explibrary;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("view.waitou.explibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ExpandableView
2 |
3 | 动画列表展开收起 ,列表右边的指示箭头可以再任何位置
4 | 当展开时如果超过屏幕的高度时父控件自动上移,滚动的父布局可以是RecyclerView,ScrollView
5 |
6 | [](https://jitpack.io/#zguop/ExpandableView)
7 |
8 | ### 效果图:
9 |
10 |  
11 |
12 |
13 | Then, add the library to your module `build.gradle`
14 | ```gradle
15 | dependencies {
16 | compile 'com.to.aboomy:explibrary:2.0.2'
17 | }
18 | ```
19 | ### 使用方式
20 |
21 | ```groovy
22 |
23 | final ExpandableView expandableView = holder.getView(R.id.item_expanble);
24 | expandableView.setAdapter(queryInfo.uniques.size(), new ExpandableView.OnBindListener() {
25 |
26 | @Override
27 | public View bindTitleView(View titleView) {
28 | if (titleView == null) {
29 | titleView = View.inflate(mContext, R.layout.item_expanble_querycar, null);
30 | }
31 | //设置箭头id
32 | holder1.mExpandingList.setArrowAnimationView(R.id.iv_arrow);
33 |
34 | //头部数据绑定...
35 |
36 | ...
37 | return titleView;
38 | }
39 |
40 | @Override
41 | public View bindChildView(int childPos, View child) {
42 | if(child == null){
43 | child = View.inflate(mContext,R.layout.item_expanble_caruniques,null);
44 | }
45 | //列表布局 数据绑定
46 | ...
47 | return child;
48 | }
49 |
50 | //返回true 列表展开收起 都将重新调用 bindTitleView bindChildView方法 适用于数据变化
51 | @Override
52 | public boolean expandableUpDataView() {
53 | return true;
54 | }
55 | });
56 | ```
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_expanble_querycar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
22 |
23 |
34 |
35 |
36 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_expanble_caruniques.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
22 |
23 |
24 |
36 |
37 |
38 |
39 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_expanble_recycle.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
21 |
22 |
29 |
30 |
31 |
38 |
39 |
46 |
47 |
48 |
49 |
50 |
54 |
55 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/view/waitou/expandableview/ModelActivity.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.ActivityCompat;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import view.waitou.explibrary.ExpandableView;
15 |
16 | /**
17 | * Created by waitou on 17/3/6.
18 | */
19 |
20 | public class ModelActivity extends AppCompatActivity {
21 |
22 |
23 | private String[] modelName = {"ALFA", "V8", "CM", "DPPPP"};
24 | private List mInfos = new ArrayList<>();
25 | private ExpandableView mExpandableView;
26 |
27 | @Override
28 | protected void onCreate(@Nullable Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_model);
31 | mExpandableView = findViewById(R.id.expan);
32 |
33 | init();
34 |
35 | mExpandableView.setAdapter(mInfos.size(), new ExpandableView.OnBindListener() {
36 |
37 | @Override
38 | public View bindTitleView(View titleView) {
39 | if(titleView == null){
40 | titleView = View.inflate(ModelActivity.this,R.layout.item_expenable,null);
41 | titleView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
42 | }
43 | mExpandableView.setArrowAnimationView(R.id.btn_fold);
44 | return titleView;
45 | }
46 |
47 | @Override
48 | public View bindChildView(int childPos, View child) {
49 | if(child == null){
50 | child = View.inflate(ModelActivity.this,R.layout.item_expanble_caruniques,null);
51 | }
52 | TextView tvRight = child.findViewById(R.id.tv_right);
53 | TextView tvLeft = child.findViewById(R.id.tv_left);
54 | boolean delivered = mInfos.get(childPos).finished;
55 | if (!delivered) {
56 | tvRight.setText("呵呵哒");
57 | tvRight.setTextColor(ActivityCompat.getColor(ModelActivity.this, R.color.orange_FF8903));
58 | tvLeft.setTextColor(ActivityCompat.getColor(ModelActivity.this, R.color.orange_FF8903));
59 | }
60 | tvLeft.setText(mInfos.get(childPos).name);
61 | return child;
62 | }
63 |
64 | @Override
65 | public boolean expandableUpDataView() {
66 | return false;
67 | }
68 | });
69 | }
70 |
71 | private void init() {
72 | for (int i = 0; i < modelName.length; i++) {
73 | QueryInfo queryInfo = new QueryInfo();
74 | queryInfo.finished = false;
75 | queryInfo.name = modelName[i];
76 | mInfos.add(queryInfo);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/view/waitou/expandableview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.View;
9 | import android.widget.Button;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | private String[] modelName = {"ALFA", "V8", "CM", "DPPPP"};
17 | private String[] uniques = {"444", "AAA", "BBBB", "444", "444", "444"};
18 | private List mInfos = new ArrayList<>();
19 | private RecyclerView mRecyclerView;
20 | private ExpandableViewAdapter expandableViewAdapter;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | Button button = (Button) findViewById(R.id.btn);
27 | button.setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | Intent intent = new Intent(MainActivity.this, ModelActivity.class);
31 | startActivity(intent);
32 | }
33 | });
34 |
35 | findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | List uniques = mInfos.get(0).uniques;
39 | UniquesInfo uniquesInfo = new UniquesInfo();
40 | uniquesInfo.snap = "添加的";
41 | uniques.add(uniquesInfo);
42 | expandableViewAdapter.addData(mInfos);
43 | }
44 | });
45 |
46 | findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | List uniques = mInfos.get(0).uniques;
50 | uniques.remove(uniques.size() - 1);
51 | expandableViewAdapter.addData(mInfos);
52 | }
53 | });
54 |
55 |
56 | mRecyclerView = (RecyclerView) findViewById(R.id.list);
57 | init();
58 | bindView();
59 | }
60 |
61 | private void bindView() {
62 | expandableViewAdapter = new ExpandableViewAdapter(this, mInfos);
63 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
64 | mRecyclerView.setAdapter(expandableViewAdapter);
65 | }
66 |
67 | private void init() {
68 | for (int i = 0; i < modelName.length; i++) {
69 | QueryInfo queryInfo = new QueryInfo();
70 | queryInfo.finished = false;
71 | queryInfo.name = modelName[i];
72 | queryInfo.uniques = new ArrayList<>();
73 | for (int j = 0; j < uniques.length; j++) {
74 | UniquesInfo uniquesInfo = new UniquesInfo();
75 | uniquesInfo.snap = uniques[j];
76 | uniquesInfo.delivered = false;
77 | queryInfo.uniques.add(uniquesInfo);
78 | }
79 | mInfos.add(queryInfo);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/explibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'//需添加的
3 | apply plugin: 'com.jfrog.bintray'//需添加的
4 | version = "2.0.2" // 修改为你的版本号
5 |
6 |
7 | android {
8 | compileSdkVersion 27
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName version
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 |
24 | def siteUrl = 'https://github.com/zguop/ExpandableView'
25 | def gitUrl = 'https://github.com/zguop/ExpandableView.git'
26 | group = "com.to.aboomy"
27 |
28 | install {
29 | repositories.mavenInstaller {
30 | // This generates POM.xml with proper parameters
31 | pom {
32 | project {
33 | packaging 'aar'
34 | // Add your description here
35 | description 'android scan qrcode libary'
36 | name 'android ExpandableView' // 可默认,项目描述
37 | url siteUrl
38 | // Set your license
39 | licenses {
40 | license {
41 | name 'The Apache Software License, Version 2.0'
42 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
43 | }
44 | }
45 | developers {
46 | developer { // 可默认,开发者信息
47 | id 'wai' //填写的一些基本信息
48 | name 'waitou'
49 | email 'waitou0@gmail.com'
50 | }
51 | }
52 | scm {
53 | connection gitUrl
54 | developerConnection gitUrl
55 | url siteUrl
56 | }
57 | }
58 | }
59 | }
60 | }
61 | task androidJavadocs(type: Javadoc) {
62 | source = android.sourceSets.main.java.srcDirs
63 | }
64 |
65 | task androidJavadocsJar(type: Jar) {
66 | classifier = 'javadoc'
67 | from androidJavadocs.destinationDir
68 | }
69 | task androidSourcesJar(type: Jar) {
70 | classifier = 'sources'
71 | from android.sourceSets.main.java.srcDirs
72 | }
73 |
74 |
75 | artifacts {
76 | archives androidSourcesJar
77 | archives androidJavadocsJar
78 |
79 | }
80 | Properties properties = new Properties()
81 | // 加载本地配置
82 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
83 | //这个是和你bintray上面创建的package(项目)是对应的
84 | bintray {
85 | user = properties.getProperty("bintray.user")
86 | key = properties.getProperty("bintray.apikey")
87 | configurations = ['archives']
88 | pkg {
89 | repo = "maven" //发布到Bintray的那个仓库里,默认账户有四个库,我们这里上传到maven库
90 | name = "ExpandableView" //需更改,这个名字就是你在Bintray上创建Package的名字,这里会查询,如果此包不存在就会创建一个。
91 | websiteUrl = siteUrl
92 | vcsUrl = gitUrl
93 | licenses = ["Apache-2.0"]
94 | publish = true
95 | }
96 | }
97 |
98 | //先执行 chmod a+x ./gradlew ./gradlew install ,然后执行 ./gradlew bintrayUpload
99 |
100 | dependencies {
101 | compileOnly 'com.android.support:recyclerview-v7:27.1.1'
102 | compileOnly 'com.android.support:appcompat-v7:27.1.1'
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/view/waitou/expandableview/ExpandableViewAdapter.java:
--------------------------------------------------------------------------------
1 | package view.waitou.expandableview;
2 |
3 | import android.content.Context;
4 | import android.support.v4.app.ActivityCompat;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import java.util.List;
13 |
14 | import view.waitou.explibrary.ExpandableView;
15 |
16 | /**
17 | * Created by waitou on 16/11/1.
18 | */
19 |
20 | public class ExpandableViewAdapter extends RecyclerView.Adapter {
21 |
22 | private List mInfos;
23 | private LayoutInflater mInflater;
24 | private Context mContext;
25 |
26 |
27 | public ExpandableViewAdapter(Context context, List infos) {
28 | this.mInfos = infos;
29 | this.mInflater = LayoutInflater.from(context);
30 | this.mContext = context;
31 | }
32 |
33 |
34 | public void addData(List mInfos){
35 | this.mInfos = mInfos;
36 | notifyDataSetChanged();
37 | }
38 |
39 |
40 | @Override
41 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
42 | return new ViewHolder(mInflater.inflate(R.layout.item_expanble_recycle, parent, false));
43 | }
44 |
45 | @Override
46 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
47 | final ViewHolder holder1 = (ViewHolder) holder;
48 | final QueryInfo queryInfo = mInfos.get(holder1.getAdapterPosition());
49 |
50 | if(position == 2){
51 | ((ViewHolder) holder).mExpandingList.setKeepChild(1);
52 | }
53 |
54 | holder1.mExpandingList.setAdapter(queryInfo.uniques.size(), new ExpandableView.OnBindListener() {
55 |
56 | @Override
57 | public View bindTitleView(View titleView) {
58 | Log.e("aa" , " titleView " + titleView);
59 | if (titleView == null) {
60 | titleView = View.inflate(mContext, R.layout.item_expanble_querycar, null);
61 | }
62 | holder1.mExpandingList.setArrowAnimationView(R.id.iv_arrow);
63 | TextView textView = titleView.findViewById(R.id.tv);
64 | textView.setText(queryInfo.name);
65 | View lineView = titleView.findViewById(R.id.line_view);
66 | if (holder1.getAdapterPosition() == getItemCount() - 1 && !holder1.mExpandingList.isExpandable()) {
67 | lineView.setVisibility(View.GONE);
68 | } else {
69 | lineView.setVisibility(View.VISIBLE);
70 | }
71 | return titleView;
72 | }
73 |
74 | @Override
75 | public View bindChildView(int childPos, View child) {
76 | Log.e("aa" , " child " + child);
77 | if(child == null){
78 | child = View.inflate(mContext,R.layout.item_expanble_caruniques,null);
79 | }
80 | TextView tvRight = child.findViewById(R.id.tv_right);
81 | TextView tvLeft = child.findViewById(R.id.tv_left);
82 | View lineView = child.findViewById(R.id.line_view);
83 |
84 | if (holder1.getAdapterPosition() != getItemCount() - 1 && childPos == queryInfo.uniques.size() - 1) {
85 | lineView.setVisibility(View.VISIBLE);
86 | } else {
87 | lineView.setVisibility(View.GONE);
88 | }
89 | UniquesInfo uniquesInfo = queryInfo.uniques.get(childPos);
90 | boolean delivered = uniquesInfo.delivered;
91 | if (!delivered) {
92 | tvRight.setText("呵呵哒");
93 | tvRight.setTextColor(ActivityCompat.getColor(mContext, R.color.orange_FF8903));
94 | tvLeft.setTextColor(ActivityCompat.getColor(mContext, R.color.orange_FF8903));
95 | }
96 | tvLeft.setText(uniquesInfo.snap);
97 | return child;
98 | }
99 |
100 | @Override
101 | public boolean expandableUpDataView() {
102 | return true;
103 | }
104 | });
105 | }
106 |
107 | @Override
108 | public int getItemCount() {
109 | return mInfos.size();
110 | }
111 |
112 | private static class ViewHolder extends RecyclerView.ViewHolder {
113 |
114 | ExpandableView mExpandingList;
115 |
116 | public ViewHolder(View itemView) {
117 | super(itemView);
118 | mExpandingList = (ExpandableView) itemView.findViewById(R.id.flex_label);
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/explibrary/src/main/java/view/waitou/explibrary/ExpandableView.java:
--------------------------------------------------------------------------------
1 | package view.waitou.explibrary;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
8 | import android.support.v4.view.ViewCompat;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.view.ViewParent;
14 | import android.view.animation.Animation;
15 | import android.view.animation.LinearInterpolator;
16 | import android.view.animation.RotateAnimation;
17 | import android.widget.LinearLayout;
18 | import android.widget.ScrollView;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * Created by waitou on 16/10/28.
25 | * 列表展开收起view
26 | */
27 |
28 | public class ExpandableView extends LinearLayout {
29 |
30 | private static final float DEGREES = 180;
31 |
32 | public static final int MOBILE_TOP = 0;
33 | public static final int MOBILE_BUM = 1;
34 |
35 | private View titleView;
36 | private List childSizeList; //记录每个子孩子的高度--叠加的
37 | private LinearLayout childLayout; //内容隐藏的view
38 | private ValueAnimator expandAnimator; //列表展开的动画
39 | private ValueAnimator collapseAnimator; //列表收起的动画
40 | private OnBindListener mOnBindListener; //所要实现的接口
41 | private int rightIconViewId; //右边点击箭头 ,需进行set设置
42 | private int dataCount; //数据集
43 | private int duration; //动画时间
44 | private int closePositionSize; //当前显示的view高度
45 | private int mFinalHeight; //子列表的最大高度
46 | private int mHeightPixels; //屏幕的高度
47 | private int expMobile; //列表模式
48 | private int keepChild; //固定多少个子View个数
49 | private boolean isAnimating; //动画是否在执行
50 | private boolean isExpanded; //列表是否展开
51 | private boolean isCalculatedSize; //是否进入测量的控制
52 |
53 | public ExpandableView(Context context) {
54 | this(context, null);
55 | }
56 |
57 | public ExpandableView(Context context, AttributeSet attrs) {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public ExpandableView(Context context, AttributeSet attrs, int defStyle) {
62 | super(context, attrs, defStyle);
63 | mHeightPixels = context.getResources().getDisplayMetrics().heightPixels;
64 | childSizeList = new ArrayList<>();
65 | init(context, attrs, defStyle);
66 | }
67 |
68 | private void init(Context context, AttributeSet attrs, int defStyle) {
69 | setOrientation(VERTICAL);
70 | childLayout = new LinearLayout(context);
71 | childLayout.setOrientation(VERTICAL);
72 | final TypedArray a = context.obtainStyledAttributes(
73 | attrs, R.styleable.ExpandableView, defStyle, 0);
74 | expMobile = a.getInt(R.styleable.ExpandableView_exp_mobile, 0);
75 | duration = a.getInteger(R.styleable.ExpandableView_exp_duration, 300);
76 | a.recycle();
77 | }
78 |
79 | @Override
80 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
81 | if (!isCalculatedSize) {
82 | childSizeList.clear();
83 | final int childCount = childLayout.getChildCount();
84 | if (childCount > 0) {
85 | int sumSize = 0;
86 | for (int i = 0; i < childCount; i++) {
87 | final View view = childLayout.getChildAt(i);
88 | measureChild(view, widthMeasureSpec, heightMeasureSpec);
89 | if (i > 0) {
90 | sumSize = childSizeList.get(i - 1);
91 | }
92 | childSizeList.add(view.getMeasuredHeight() + sumSize);
93 | }
94 | mFinalHeight = childSizeList.get(childCount - 1);
95 | } else {
96 | mFinalHeight = 0;
97 | }
98 | int layoutHeight = mFinalHeight;
99 | if (keepChild > 0 && keepChild <= childSizeList.size()) {
100 | closePositionSize = childSizeList.get(keepChild - 1);
101 | layoutHeight = closePositionSize;
102 | }
103 | initValueAnimator();
104 | if (isExpandable()) {
105 | setLayoutSize(layoutHeight);
106 | } else {
107 | setLayoutSize(closePositionSize);
108 | }
109 | isCalculatedSize = true;
110 | }
111 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
112 | }
113 |
114 | public void setAdapter(int dataCount, OnBindListener bindListener) {
115 | this.dataCount = dataCount;
116 | this.mOnBindListener = bindListener;
117 | expandableUpdateView();
118 | addViewContent();
119 | setTitleClick();
120 | }
121 |
122 | /**
123 | * 更改模式 设置点击列表 展开头部在下 还是在上 两种值可使用
124 | * MOBILE_TOP
125 | * MOBILE_BUM
126 | *
127 | * @param expMobile 模式值
128 | */
129 | public void setExpMobile(int expMobile) {
130 | if (this.expMobile != expMobile) {
131 | removeAllViews();
132 | addViewContent();
133 | }
134 | }
135 |
136 | /**
137 | * 设置点击部分的 隐藏 显示Visibility
138 | */
139 | public void setTitleViewVisibility(int visibility) {
140 | titleView.setVisibility(visibility);
141 | }
142 |
143 | /**
144 | * 设置箭头的view
145 | */
146 | public void setArrowAnimationView(int rightIconViewId) {
147 | this.rightIconViewId = rightIconViewId;
148 | }
149 |
150 | /**
151 | * 列表是否打开关闭
152 | */
153 | public boolean isExpandable() {
154 | return isExpanded;
155 | }
156 |
157 | /**
158 | * 设置动画时间,重新初始化动画
159 | */
160 | public void setDuration(int duration) {
161 | if (this.duration != duration) {
162 | this.duration = duration;
163 | initValueAnimator();
164 | }
165 | }
166 |
167 | /**
168 | * 设置保留view的个数 滑动的起始点,例1 child的第一个位置始终显示
169 | */
170 | public void setKeepChild(final int childNumber) {
171 | this.keepChild = childNumber;
172 | }
173 |
174 | private void initChildView() {
175 | if (dataCount > 0) {
176 | int childCount = childLayout.getChildCount();
177 | if (dataCount < childCount) {
178 | childLayout.removeViews(dataCount, childCount - dataCount);
179 | }
180 | for (int i = 0; i < dataCount; i++) {
181 | View holder = null;
182 | if (childCount - 1 >= i) {
183 | holder = childLayout.getChildAt(i);
184 | }
185 | View child = mOnBindListener.bindChildView(i, holder);
186 | if (holder != child) {
187 | childLayout.removeView(holder);
188 | holder = child;
189 | }
190 | if (holder != null && holder.getParent() == null) {
191 | childLayout.addView(holder, i);
192 | }
193 | }
194 | if (childSizeList.size() != dataCount) {
195 | isCalculatedSize = false;
196 | }
197 | } else {
198 | childLayout.removeAllViews();
199 | childSizeList.clear();
200 | }
201 | }
202 |
203 | private void initClickView() {
204 | View childAt = mOnBindListener.bindTitleView(titleView);
205 | if (titleView != childAt) {
206 | int titleViewIndex = indexOfChild(titleView);
207 | titleView = childAt;
208 | if (titleViewIndex != -1) {
209 | removeViewAt(titleViewIndex);
210 | addView(titleView, titleViewIndex);
211 | }
212 | }
213 | }
214 |
215 | private void setTitleClick() {
216 | titleView.setOnClickListener(new OnClickListener() {
217 | @Override
218 | public void onClick(View v) {
219 | if (isAnimating) {
220 | return;
221 | }
222 | if (isExpandable()) {
223 | isExpanded = false;
224 | collapse();
225 | } else {
226 | isExpanded = true;
227 | expand();
228 | }
229 | }
230 | });
231 | }
232 |
233 | /**
234 | * 根据模式顺序添加view
235 | */
236 | private void addViewContent() {
237 | int childIndex = indexOfChild(titleView);
238 | if (expMobile == MOBILE_TOP) {
239 | if (childIndex > 0) {
240 | removeView(titleView);
241 | }
242 | if (childIndex != 0) {
243 | addView(titleView, 0);
244 | }
245 | if (childLayout.getParent() == null) {
246 | addView(childLayout);
247 | }
248 | } else if (expMobile == MOBILE_BUM) {
249 | if (childIndex < 1) {
250 | removeView(titleView);
251 | }
252 | if (childLayout.getParent() == null) {
253 | addView(childLayout);
254 | }
255 | if (childIndex != 1) {
256 | addView(titleView);
257 | }
258 | }
259 | }
260 |
261 | /**
262 | * 初始化列表展开动画
263 | */
264 | private void initValueAnimator() {
265 | expandAnimator = slideAnimator(closePositionSize, mFinalHeight, true);
266 | collapseAnimator = slideAnimator(mFinalHeight, closePositionSize, false);
267 | }
268 |
269 | /**
270 | * 列表展开
271 | */
272 | private void expand() {
273 | expandAnimator.start();
274 | View rightIcon = findViewById(rightIconViewId);
275 | if (rightIcon == null) {
276 | return;
277 | }
278 | int x = rightIcon.getWidth() / 2;
279 | int y = rightIcon.getHeight() / 2;
280 | RotateAnimation expandRotateAnimation = new RotateAnimation(0f, DEGREES, x, y);
281 | expandRotateAnimation.setInterpolator(new LinearInterpolator());
282 | expandRotateAnimation.setRepeatCount(Animation.ABSOLUTE);
283 | expandRotateAnimation.setFillAfter(true);
284 | expandRotateAnimation.setDuration(duration);
285 | rightIcon.startAnimation(expandRotateAnimation);
286 | }
287 |
288 | /**
289 | * 列表收起
290 | */
291 | private void collapse() {
292 | collapseAnimator.start();
293 | View rightIcon = findViewById(rightIconViewId);
294 | if (rightIcon == null) {
295 | return;
296 | }
297 | int x = rightIcon.getWidth() / 2;
298 | int y = rightIcon.getHeight() / 2;
299 | RotateAnimation collapseRotateAnimation = new RotateAnimation(DEGREES, 0f, x, y);
300 | collapseRotateAnimation.setInterpolator(new LinearInterpolator());
301 | collapseRotateAnimation.setRepeatCount(Animation.ABSOLUTE);
302 | collapseRotateAnimation.setFillAfter(true);
303 | collapseRotateAnimation.setDuration(duration);
304 | rightIcon.startAnimation(collapseRotateAnimation);
305 | }
306 |
307 | private ValueAnimator slideAnimator(int start, int end, final boolean status) {
308 | ValueAnimator animator = ValueAnimator.ofInt(start, end);
309 | animator.setDuration(duration);
310 | animator.setInterpolator(new LinearInterpolator());
311 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
312 | @Override
313 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
314 | int value = (Integer) valueAnimator.getAnimatedValue();
315 | ViewGroup.LayoutParams layoutParams = childLayout.getLayoutParams();
316 | layoutParams.height = value;
317 | childLayout.setLayoutParams(layoutParams);
318 | ViewCompat.postInvalidateOnAnimation(childLayout);
319 | }
320 | });
321 |
322 | animator.addListener(new AnimatorListenerAdapter() {
323 | @Override
324 | public void onAnimationEnd(Animator animator) {
325 | isAnimating = false;
326 | if (!status) {
327 | if (mOnBindListener.expandableUpDataView()) {
328 | expandableUpdateView();
329 | }
330 | } else {
331 | adjustItemPosIfHidden();
332 | }
333 | }
334 |
335 | @Override
336 | public void onAnimationStart(Animator animator) {
337 | isAnimating = true;
338 | if (status && mOnBindListener.expandableUpDataView()) {
339 | expandableUpdateView();
340 | }
341 | }
342 | });
343 | return animator;
344 | }
345 |
346 | /**
347 | * 展开超出频幕高度时 移动到当前列表的最底部
348 | */
349 | private void adjustItemPosIfHidden() {
350 | int[] itemPos = new int[2];
351 | childLayout.getLocationOnScreen(itemPos);
352 | int itemY = itemPos[1];
353 | int endPosition;
354 | if (expMobile != MOBILE_TOP) {
355 | int measuredHeight = titleView.getHeight();
356 | endPosition = itemY + mFinalHeight + measuredHeight;
357 | } else {
358 | endPosition = itemY + mFinalHeight;
359 | }
360 | if (endPosition > mHeightPixels) {
361 | int delta = endPosition - mHeightPixels;
362 | scrollBy(getParent(), delta);
363 | }
364 | }
365 |
366 | /**
367 | * 寻找可滑动的父view
368 | */
369 | private void scrollBy(ViewParent parent, int delta) {
370 | if (parent == null) {
371 | return;
372 | }
373 | if (parent instanceof RecyclerView) {
374 | RecyclerView recyclerView = (RecyclerView) parent;
375 | recyclerView.smoothScrollBy(0, delta);
376 | } else if (parent instanceof ScrollView) {
377 | ScrollView scrollView = (ScrollView) parent;
378 | scrollView.smoothScrollBy(0, delta);
379 | } else {
380 | scrollBy(parent.getParent(), delta);
381 | }
382 | }
383 |
384 | /**
385 | * 重新刷新列表数据
386 | */
387 | private void expandableUpdateView() {
388 | initClickView();
389 | initChildView();
390 | }
391 |
392 | /**
393 | * 设置view的高度
394 | */
395 | private void setLayoutSize(int size) {
396 | childLayout.getLayoutParams().height = size;
397 | }
398 |
399 | /**
400 | * 需要实现的接口
401 | */
402 | public interface OnBindListener {
403 |
404 | /**
405 | * 绑定头部view
406 | */
407 | View bindTitleView(View titleView);
408 |
409 | /**
410 | * 绑定子View
411 | */
412 | View bindChildView(int childPos, View child);
413 |
414 | /**
415 | * return true 每次点击都会重新调用 bindTitleView bindChildView
416 | */
417 | boolean expandableUpDataView();
418 |
419 | }
420 |
421 | @Override
422 | protected void onDetachedFromWindow() {
423 | super.onDetachedFromWindow();
424 | expandAnimator.cancel();
425 | collapseAnimator.cancel();
426 | }
427 | }
428 |
--------------------------------------------------------------------------------