├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── SoftLinearLayout.gif
├── SoftLinearLayout1.gif
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wkp
│ │ └── bottomlinearlayout
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wkp
│ │ │ └── bottomlinearlayout
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wkp
│ └── bottomlinearlayout
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── softlinearlayout-lib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── wkp
│ └── softlinearlayout
│ ├── util
│ └── SPUtils.java
│ └── view
│ └── SoftLinearLayout.java
└── res
├── drawable-v24
└── ic_launcher_foreground.xml
├── drawable
└── ic_launcher_background.xml
├── mipmap-anydpi-v26
├── ic_launcher.xml
└── ic_launcher_round.xml
├── mipmap-hdpi
├── ic_launcher.png
└── ic_launcher_round.png
├── mipmap-mdpi
├── ic_launcher.png
└── ic_launcher_round.png
├── mipmap-xhdpi
├── ic_launcher.png
└── ic_launcher_round.png
├── mipmap-xxhdpi
├── ic_launcher.png
└── ic_launcher_round.png
├── mipmap-xxxhdpi
├── ic_launcher.png
└── ic_launcher_round.png
└── values
├── attrs.xml
├── colors.xml
├── strings.xml
└── styles.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SoftLinearLayout [  ](https://bintray.com/wkp/maven/SoftLinearLayout/_latestVersion)
2 | 底部控件随输入法高度变化而变化,比QQ聊天界面更完美
3 | ## 演示图
4 | 无状态栏示例图:
5 | 
6 | 有状态栏示例图:
7 | 
8 | ## Gradle集成
9 | ```groovy
10 | dependencies{
11 | compile 'com.wkp:SoftLinearLayout:1.0.3'
12 | //Android Studio3.0+可用以下方式
13 | //implementation 'com.wkp:SoftLinearLayout:1.0.3'
14 | }
15 |
16 | //如集成失败或不愿意等待,请加上我的maven仓库地址
17 | maven { url "https://dl.bintray.com/wkp/maven" }
18 | ```
19 | Note:可能存在Jcenter还在审核阶段,这时会集成失败!
20 | ## 使用详解
21 | > 属性讲解
22 | ```xml
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ```
34 | Note:每个属性都有对应的java设置代码!
35 | > 布局
36 | ```xml
37 |
38 |
46 |
47 |
55 |
56 |
60 |
61 |
67 |
68 |
69 |
70 |
71 |
72 |
77 |
78 |
83 |
84 |
85 |
86 |
93 |
94 |
101 |
102 |
103 |
104 |
105 | ```
106 | Note:SoftLinearLayout一般为根布局,它的子布局最多2个,否则会异常!
107 | > 代码示例
108 | ```java
109 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
110 | public class MainActivity extends AppCompatActivity {
111 |
112 | private SoftLinearLayout mSll;
113 | private String[] mStrings = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("\\B");
114 |
115 | @Override
116 | protected void onCreate(Bundle savedInstanceState) {
117 | super.onCreate(savedInstanceState);
118 | setContentView(R.layout.activity_main);
119 | //设置状态栏颜色,有状态栏app:wkp_hasStatusBar="true"
120 | // StatusBarUtil.setColor(this,getResources().getColor(R.color.colorPrimary));
121 | //设置状态栏半透明,没有状态栏app:wkp_hasStatusBar="false"
122 | StatusBarUtil.setTranslucent(this);
123 |
124 | ListView lv = findViewById(R.id.lv);
125 | lv.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,mStrings));
126 | mSll = findViewById(R.id.sll);
127 | //没有状态栏
128 | mSll.hasStatusBar(false);
129 | //设置开关改变监听
130 | mSll.setOnToggleChangedListener(new SoftLinearLayout.OnToggleChangedListener() {
131 | @Override
132 | public void onToggleChanged(boolean isToggle) {
133 | Log.d("MainActivity", "isToggle:" + isToggle);
134 | }
135 | });
136 | }
137 |
138 | //点击开/关
139 | public void sure(View view) {
140 | mSll.toggle();
141 | }
142 | }
143 |
144 | ```
145 | Note:还有其他API请根据需要自行参考!
146 | ## 感谢
147 | 沉浸式状态栏设置库(Github地址):laobie/StatusBarUtil
148 | ## 寄语
149 | 控件支持直接代码创建,还有更多API请观看SoftLinearLayout.java内的注释说明。
150 | 欢迎大家使用,感觉好用请给个Star鼓励一下,谢谢!
151 | 大家如果有更好的意见或建议以及好的灵感,请邮箱作者,谢谢!
152 | QQ邮箱:1535514884@qq.com
153 | 163邮箱:15889686524@163.com
154 | Gmail邮箱:wkp15889686524@gmail.com
155 |
156 | ## 版本更新
157 | * v1.0.3
158 | 修复当沉浸式状态栏为透明或半透明时所引起的布局BUG(需设置属性wkp_hasStatusBar或代码设置).
159 | 感谢HappyJess提供的建议.
160 | * v1.0.2
161 | 新增动画功能,可设置动画时长,详情参考属性讲解.
162 | * v1.0.1
163 | 新创建随软键盘高度变化而变化控件库.
164 | ## License
165 |
166 | Copyright 2017 wkp
167 |
168 | Licensed under the Apache License, Version 2.0 (the "License");
169 | you may not use this file except in compliance with the License.
170 | You may obtain a copy of the License at
171 |
172 | http://www.apache.org/licenses/LICENSE-2.0
173 |
174 | Unless required by applicable law or agreed to in writing, software
175 | distributed under the License is distributed on an "AS IS" BASIS,
176 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
177 | See the License for the specific language governing permissions and
178 | limitations under the License.
179 |
180 |
--------------------------------------------------------------------------------
/SoftLinearLayout.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/SoftLinearLayout.gif
--------------------------------------------------------------------------------
/SoftLinearLayout1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/SoftLinearLayout1.gif
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 26
9 | defaultConfig {
10 | applicationId "com.wkp.bottomlinearlayout"
11 | minSdkVersion 15
12 | targetSdkVersion 26
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | lintOptions {
25 | abortOnError false
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(include: ['*.jar'], dir: 'libs')
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32 | //noinspection GradleCompatible
33 | implementation 'com.android.support:appcompat-v7:26.1.0'
34 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
35 | testImplementation 'junit:junit:4.12'
36 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
37 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
38 | implementation project(':softlinearlayout-lib')
39 | compile 'com.jaeger.statusbarutil:library:1.4.0'
40 | }
41 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wkp/bottomlinearlayout/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.wkp.bottomlinearlayout
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.wkp.bottomlinearlayout", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wkp/bottomlinearlayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wkp.bottomlinearlayout;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.annotation.RequiresApi;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.ArrayAdapter;
10 | import android.widget.ListView;
11 |
12 | import com.jaeger.library.StatusBarUtil;
13 | import com.wkp.softlinearlayout.view.SoftLinearLayout;
14 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | private SoftLinearLayout mSll;
18 | private String[] mStrings = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("\\B");
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | //设置状态栏颜色,有状态栏app:wkp_hasStatusBar="true"
25 | // StatusBarUtil.setColor(this,getResources().getColor(R.color.colorPrimary));
26 | //设置状态栏半透明,没有状态栏app:wkp_hasStatusBar="false"
27 | StatusBarUtil.setTranslucent(this);
28 |
29 | ListView lv = findViewById(R.id.lv);
30 | lv.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,mStrings));
31 | mSll = findViewById(R.id.sll);
32 | //没有状态栏
33 | mSll.hasStatusBar(false);
34 | //设置开关改变监听
35 | mSll.setOnToggleChangedListener(new SoftLinearLayout.OnToggleChangedListener() {
36 | @Override
37 | public void onToggleChanged(boolean isToggle) {
38 | Log.d("MainActivity", "isToggle:" + isToggle);
39 | }
40 | });
41 | }
42 |
43 | //点击开/关
44 | public void sure(View view) {
45 | mSll.toggle();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
36 |
41 |
42 |
47 |
48 |
49 |
50 |
57 |
58 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BottomLinearLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wkp/bottomlinearlayout/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.wkp.bottomlinearlayout
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.1.51'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | classpath 'com.novoda:bintray-release:0.7.0'
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 09 09:15:12 CST 2017
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':softlinearlayout-lib'
2 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/build.gradle:
--------------------------------------------------------------------------------
1 | //apply plugin: 'com.android.application'
2 | apply plugin: 'com.android.library'
3 | apply plugin: 'com.novoda.bintray-release'
4 |
5 | android {
6 | compileSdkVersion 26
7 |
8 |
9 |
10 | defaultConfig {
11 | // applicationId "com.wkp.softlinearlayout"
12 | minSdkVersion 15
13 | targetSdkVersion 26
14 | versionCode 3
15 | versionName "1.0.3"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | lintOptions {
27 | abortOnError false
28 | }
29 |
30 |
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 | implementation 'com.android.support:appcompat-v7:26.1.0'
36 | }
37 |
38 | publish {
39 | userOrg = 'wkp'
40 | groupId = 'com.wkp'
41 | artifactId = 'SoftLinearLayout'
42 | publishVersion = '1.0.3'
43 | desc = 'a library to create a magic LinearLayout'
44 | website = 'https://github.com/wkp111/SoftLinearLayout'
45 | }
46 |
47 | tasks.withType(Javadoc) {
48 | options.addStringOption('Xdoclint:none', '-quiet')
49 | options.addStringOption('encoding', 'UTF-8')
50 | options.addStringOption('charSet', 'UTF-8')
51 | }
--------------------------------------------------------------------------------
/softlinearlayout-lib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/java/com/wkp/softlinearlayout/util/SPUtils.java:
--------------------------------------------------------------------------------
1 | package com.wkp.softlinearlayout.util;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.content.SharedPreferences.Editor;
6 |
7 | /**
8 | * 首选项工具类
9 | *
10 | * @author wkp111
11 | */
12 | public class SPUtils {
13 | /**
14 | * 获取首选项
15 | *
16 | * @param context
17 | * @return SharedPreferences sp
18 | */
19 | public static SharedPreferences getSP(Context context) {
20 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
21 | return sp;
22 | }
23 |
24 | /**
25 | * 获取首选项中String类型值,对应键值为key
26 | *
27 | * @param context
28 | * @param key
29 | * @return key对应的值(String)
30 | */
31 | public static String getString(Context context, String key, String defaultValue) {
32 | SharedPreferences sp = getSP(context);
33 | String string = sp.getString(key, defaultValue);
34 | return string;
35 | }
36 |
37 | /**
38 | * 获取首选项中String类型值,对应键值为key
39 | *
40 | * @param context
41 | * @param key
42 | * @return key对应的值(String)
43 | */
44 | public static String getString(Context context, String key) {
45 | SharedPreferences sp = getSP(context);
46 | String string = sp.getString(key, "");
47 | return string;
48 | }
49 |
50 | /**
51 | * 获取首选项中boolean类型值,对应键值为key
52 | *
53 | * @param context
54 | * @param key
55 | * @return key对应的值(boolean)
56 | */
57 | public static boolean getBoolean(Context context, String key) {
58 | SharedPreferences sp = getSP(context);
59 | boolean b = sp.getBoolean(key, false);
60 | return b;
61 | }
62 |
63 | /**
64 | * 获取首选项中boolean类型值,对应键值为key
65 | *
66 | * @param context
67 | * @param key
68 | * @return key对应的值(boolean)
69 | */
70 | public static boolean getBoolean(Context context, String key, boolean defaultValue) {
71 | SharedPreferences sp = getSP(context);
72 | boolean b = sp.getBoolean(key, defaultValue);
73 | return b;
74 | }
75 |
76 | /**
77 | * 获取首选项中int类型值,对应键值为key
78 | *
79 | * @param context
80 | * @param key
81 | * @return key对应的值(int)
82 | */
83 | public static int getInt(Context context, String key, int defaultValue) {
84 | SharedPreferences sp = getSP(context);
85 | int i = sp.getInt(key, defaultValue);
86 | return i;
87 | }
88 |
89 | /**
90 | * 获取首选项中int类型值,对应键值为key
91 | *
92 | * @param context
93 | * @param key
94 | * @return key对应的值(int)
95 | */
96 | public static int getInt(Context context, String key) {
97 | SharedPreferences sp = getSP(context);
98 | int i = sp.getInt(key, 0);
99 | return i;
100 | }
101 |
102 | /**
103 | * 获取首选项中long类型值,对应键值为key
104 | *
105 | * @param context
106 | * @param key
107 | * @return key对应的值(long)
108 | */
109 | public static long getLong(Context context, String key, int defaultValue) {
110 | SharedPreferences sp = getSP(context);
111 | long i = sp.getLong(key, defaultValue);
112 | return i;
113 | }
114 |
115 | /**
116 | * 获取首选项中long类型值,对应键值为key
117 | *
118 | * @param context
119 | * @param key
120 | * @return key对应的值(long)
121 | */
122 | public static long getLong(Context context, String key) {
123 | SharedPreferences sp = getSP(context);
124 | long i = sp.getLong(key, 0);
125 | return i;
126 | }
127 |
128 | /**
129 | * 获取首选项中float类型值,对应键值为key
130 | *
131 | * @param context
132 | * @param key
133 | * @return key对应的值(float)
134 | */
135 | public static float getFloat(Context context, String key, int defaultValue) {
136 | SharedPreferences sp = getSP(context);
137 | float i = sp.getFloat(key, defaultValue);
138 | return i;
139 | }
140 |
141 | /**
142 | * 获取首选项中float类型值,对应键值为key
143 | *
144 | * @param context
145 | * @param key
146 | * @return key对应的值(float)
147 | */
148 | public static float getFloat(Context context, String key) {
149 | SharedPreferences sp = getSP(context);
150 | float i = sp.getFloat(key, 0);
151 | return i;
152 | }
153 |
154 | /**
155 | * 向首选项中编辑数据(键值对)(值可以是String boolean int)
156 | *
157 | * @param context
158 | * @param key
159 | * @param value
160 | */
161 | public static void put(Context context, String key, Object value) {
162 | SharedPreferences sp = getSP(context);
163 | Editor editor = sp.edit();
164 |
165 | if (value instanceof String) {
166 | editor.putString(key, (String) value);
167 | } else if (value instanceof Boolean) {
168 | editor.putBoolean(key, (boolean) value);
169 | } else if (value instanceof Integer) {
170 | editor.putInt(key, (int) value);
171 | } else if (value instanceof Long) {
172 | editor.putLong(key, (long) value);
173 | } else if (value instanceof Float) {
174 | editor.putFloat(key, (float) value);
175 | }
176 |
177 | editor.commit();
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/java/com/wkp/softlinearlayout/view/SoftLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.wkp.softlinearlayout.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Rect;
6 | import android.os.Build;
7 | import android.support.annotation.Nullable;
8 | import android.support.annotation.RequiresApi;
9 | import android.transition.ChangeBounds;
10 | import android.transition.TransitionManager;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.Window;
15 | import android.view.inputmethod.InputMethodManager;
16 | import android.widget.LinearLayout;
17 |
18 | import com.wkp.softlinearlayout.R;
19 | import com.wkp.softlinearlayout.util.SPUtils;
20 |
21 | /**
22 | * Created by user on 2017/11/10.
23 | */
24 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
25 | public class SoftLinearLayout extends LinearLayout {
26 | private static final int DEFAULT_CHILD_COUNT = 2;
27 | private static final int DEFAULT_SECOND_CHILD_HEIGHT = 740;
28 | private static final int DEFAULT_SECOND_CHILD_MIN_HEIGHT = 400;
29 | private static final int DEFAULT_SECOND_CHILD_MAX_HEIGHT = 800;
30 | private static final int DEFAULT_SECOND_CHILD_MID_HEIGHT = 600;
31 | private static final long DEFAULT_SHOW_SOFT_DURATION = 50;
32 | private static final long DEFAULT_TOGGLE_DURATION = 200;
33 | private static final String SP_KEY_SECOND_HEIGHT = "second_height";
34 | private int secondChildHeight = DEFAULT_SECOND_CHILD_HEIGHT;
35 | private int secondChildMinHeight = DEFAULT_SECOND_CHILD_MIN_HEIGHT;
36 | private int secondChildMaxHeight = DEFAULT_SECOND_CHILD_MAX_HEIGHT;
37 | private long showSoftDuration = DEFAULT_SHOW_SOFT_DURATION;
38 | private long toggleDuration = DEFAULT_TOGGLE_DURATION;
39 | private int firstChildHeight;
40 | private boolean secondChildState;
41 | private Context mContext;
42 | private OnToggleChangedListener mListener;
43 | private boolean mHasStatusBar = true;
44 |
45 | public SoftLinearLayout(Context context) {
46 | this(context, null);
47 | }
48 |
49 | public SoftLinearLayout(Context context, @Nullable AttributeSet attrs) {
50 | this(context, attrs, 0);
51 | }
52 |
53 | public SoftLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | mContext = context;
56 | initAttr(attrs);
57 | init();
58 | }
59 |
60 | /**
61 | * 判断控件是否可见
62 | *
63 | * @param visibility
64 | */
65 | @Override
66 | protected void onWindowVisibilityChanged(int visibility) {
67 | super.onWindowVisibilityChanged(visibility);
68 | if (visibility == GONE) {
69 | SPUtils.put(mContext, SP_KEY_SECOND_HEIGHT, secondChildHeight);
70 | }
71 | }
72 |
73 | /**
74 | * 初始化属性
75 | *
76 | * @param attrs
77 | */
78 | private void initAttr(AttributeSet attrs) {
79 | TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SoftLinearLayout);
80 | if (typedArray != null) {
81 | int minHeight = typedArray.getInteger(R.styleable.SoftLinearLayout_wkp_minHeight, DEFAULT_SECOND_CHILD_MIN_HEIGHT);
82 | int maxHeight = typedArray.getInteger(R.styleable.SoftLinearLayout_wkp_maxHeight, DEFAULT_SECOND_CHILD_MAX_HEIGHT);
83 | int showSoftDuration = typedArray.getInteger(R.styleable.SoftLinearLayout_wkp_showSoftDuration, (int) DEFAULT_SHOW_SOFT_DURATION);
84 | int toggleDuration = typedArray.getInteger(R.styleable.SoftLinearLayout_wkp_toggleDuration, (int) DEFAULT_TOGGLE_DURATION);
85 | boolean hasStatusBar = typedArray.getBoolean(R.styleable.SoftLinearLayout_wkp_hasStatusBar, true);
86 | setMinHeight(minHeight);
87 | setMaxHeight(maxHeight);
88 | setShowSoftAnimDuration(showSoftDuration);
89 | setToggleAnimDuration(toggleDuration);
90 | hasStatusBar(hasStatusBar);
91 | typedArray.recycle();
92 | }
93 | }
94 |
95 | /**
96 | * 初始化其他
97 | */
98 | private void init() {
99 | setOrientation(LinearLayout.VERTICAL);
100 | secondChildHeight = SPUtils.getInt(mContext, SP_KEY_SECOND_HEIGHT, DEFAULT_SECOND_CHILD_HEIGHT);
101 | }
102 |
103 | @Override
104 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
105 | super.onSizeChanged(w, h, oldw, oldh);
106 | firstChildHeight = getTotalHeight() - getTitleBarHeight(); //固定高度
107 | }
108 |
109 | @Override
110 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
111 | if (getChildCount() > DEFAULT_CHILD_COUNT) {
112 | throw new IllegalStateException("SoftLinearLayout can not has three or more children!");
113 | }
114 | int visibility = SoftLinearLayout.this.getVisibility();
115 | int divTopHeight = 0;
116 | int divBotHeight = 0;
117 | if (visibility == VISIBLE) {
118 | int topHeight = getVisibleHeight() - getTitleBarHeight();
119 | int bottomHeight = getTotalHeight() - getVisibleHeight();
120 | if (isSoftShowing()) {
121 | if (secondChildState && mListener != null) {
122 | mListener.onToggleChanged(false);
123 | }
124 | secondChildState = false;
125 | divBotHeight = topHeight;
126 | divTopHeight = firstChildHeight - topHeight;
127 | setSecondChildHeight(bottomHeight);
128 | setTransition(showSoftDuration);
129 | } else {
130 | if (secondChildState) {
131 | divBotHeight = topHeight - secondChildHeight;
132 | divTopHeight = secondChildHeight;
133 | } else {
134 | divBotHeight = topHeight;
135 | divTopHeight = 0;
136 | }
137 | setTransition(toggleDuration);
138 | }
139 | }
140 | for (int i = 0; i < getChildCount(); i++) {
141 | View view = getChildAt(i);
142 | ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
143 | switch (i) {
144 | case 0:
145 | view.layout(l, t - divTopHeight, r, t - divTopHeight + firstChildHeight);
146 | if (layoutParams.height != firstChildHeight) {
147 | layoutParams.height = firstChildHeight;
148 | view.setLayoutParams(layoutParams);
149 | }
150 | break;
151 | case 1:
152 | view.layout(l, t + divBotHeight, r, t + divBotHeight + secondChildHeight);
153 | if (layoutParams.height != secondChildHeight) {
154 | layoutParams.height = secondChildHeight;
155 | view.setLayoutParams(layoutParams);
156 | }
157 | break;
158 | }
159 | }
160 | }
161 |
162 | /**
163 | * 设置第二个孩子高度
164 | *
165 | * @param height
166 | */
167 | private void setSecondChildHeight(int height) {
168 | secondChildHeight = height < secondChildMinHeight ? secondChildMinHeight : (height > secondChildMaxHeight ? secondChildMaxHeight : height);
169 | }
170 |
171 | /**
172 | * 获取状态栏高度
173 | *
174 | * @return
175 | */
176 | private int getStatusBarHeight() {
177 | Rect outRect = new Rect();
178 | getWindowVisibleDisplayFrame(outRect);
179 | return outRect.top;
180 | }
181 |
182 | /**
183 | * 获取ToolBar高度(包含状态栏高度)
184 | *
185 | * @return
186 | */
187 | private int getTitleBarHeight() {
188 | View rootView = getRootView();
189 | if (rootView != null) {
190 | View window = rootView.findViewById(Window.ID_ANDROID_CONTENT);
191 | if (window != null) {
192 | return window.getTop() + (mHasStatusBar ? getStatusBarHeight() : 0);
193 | }
194 | }
195 | return mHasStatusBar ? getStatusBarHeight() : 0;
196 | }
197 |
198 | /**
199 | * 获取窗口可见区域高度(包含状态栏和ToolBar高度)
200 | *
201 | * @return
202 | */
203 | private int getVisibleHeight() {
204 | Rect outRect = new Rect();
205 | getWindowVisibleDisplayFrame(outRect);
206 | return outRect.bottom;
207 | }
208 |
209 | /**
210 | * 获取屏幕高度(不包含虚拟键高度,包含状态栏和ToolBar高度)
211 | *
212 | * @return
213 | */
214 | private int getTotalHeight() {
215 | return getResources().getDisplayMetrics().heightPixels;
216 | }
217 |
218 | /**
219 | * 隐藏软键盘
220 | */
221 | private void hideSoft() {
222 | InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
223 | if (imm != null) {
224 | imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
225 | }
226 | }
227 |
228 | /**
229 | * 设置动画时长
230 | *
231 | * @param duration
232 | */
233 | private void setTransition(long duration) {
234 | ChangeBounds changeBounds = new ChangeBounds();
235 | changeBounds.setDuration(duration);
236 | TransitionManager.beginDelayedTransition(SoftLinearLayout.this, changeBounds);
237 | }
238 |
239 | /**
240 | * 判断软键盘当前是否显示
241 | *
242 | * @return
243 | */
244 | public boolean isSoftShowing() {
245 | return getTotalHeight() - getVisibleHeight() != 0;
246 | }
247 |
248 | /**
249 | * 设置当前状态
250 | *
251 | * @param state
252 | */
253 | public void toggle(boolean state) {
254 | if (secondChildState != state) {
255 | if (mListener != null) {
256 | mListener.onToggleChanged(state);
257 | }
258 | }
259 | secondChildState = state;
260 | if (state) {
261 | if (isSoftShowing()) {
262 | hideSoft();
263 | } else {
264 | requestLayout();
265 | }
266 | } else {
267 | requestLayout();
268 | }
269 | }
270 |
271 | /**
272 | * 设置当前反状态
273 | */
274 | public void toggle() {
275 | toggle(!secondChildState);
276 | }
277 |
278 | /**
279 | * 获取当前状态
280 | *
281 | * @return
282 | */
283 | public boolean isToggle() {
284 | return secondChildState;
285 | }
286 |
287 | /**
288 | * 是否有沉浸式状态栏(默认true)
289 | * @param hasStatusBar
290 | * @return
291 | */
292 | public SoftLinearLayout hasStatusBar(boolean hasStatusBar) {
293 | mHasStatusBar = hasStatusBar;
294 | return this;
295 | }
296 |
297 | /**
298 | * 设置可变高度的极限小高度
299 | *
300 | * @param minHeight
301 | */
302 | public SoftLinearLayout setMinHeight(int minHeight) {
303 | secondChildMinHeight = minHeight < DEFAULT_SECOND_CHILD_MIN_HEIGHT ? DEFAULT_SECOND_CHILD_MIN_HEIGHT : (minHeight > DEFAULT_SECOND_CHILD_MID_HEIGHT ?
304 | DEFAULT_SECOND_CHILD_MID_HEIGHT : minHeight);
305 | return this;
306 | }
307 |
308 | /**
309 | * 设置可变高度的极限大高度
310 | *
311 | * @param maxHeight
312 | */
313 | public SoftLinearLayout setMaxHeight(int maxHeight) {
314 | secondChildMaxHeight = maxHeight < DEFAULT_SECOND_CHILD_MID_HEIGHT ? DEFAULT_SECOND_CHILD_MID_HEIGHT : (maxHeight > DEFAULT_SECOND_CHILD_MAX_HEIGHT ?
315 | DEFAULT_SECOND_CHILD_MAX_HEIGHT : maxHeight);
316 | return this;
317 | }
318 |
319 | /**
320 | * 设置软键盘显示阶段的控件动画时长(需自己调到与键盘动画同步,但大部分输入法键盘动画时长不一致,最小0,最大200)
321 | * @param duration
322 | * @return
323 | */
324 | public SoftLinearLayout setShowSoftAnimDuration(long duration) {
325 | showSoftDuration = duration < 0 ? 0 : (duration > 200 ? 200 : duration);
326 | return this;
327 | }
328 |
329 | /**
330 | * 设置开关阶段的控件动画时长(最小0,最大500)
331 | * @param duration
332 | * @return
333 | */
334 | public SoftLinearLayout setToggleAnimDuration(long duration) {
335 | toggleDuration = duration < 0 ? 0 : (duration > 500 ? 500 : duration);
336 | return this;
337 | }
338 |
339 | /**
340 | * 状态改变监听
341 | */
342 | public interface OnToggleChangedListener {
343 | void onToggleChanged(boolean isToggle);
344 | }
345 |
346 | /**
347 | * 设置状态改变监听
348 | *
349 | * @param listener
350 | */
351 | public void setOnToggleChangedListener(OnToggleChangedListener listener) {
352 | mListener = listener;
353 | }
354 | }
355 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkp111/SoftLinearLayout/6b6f2b4bebadd20ec2a346df2d6e00b2f686420d/softlinearlayout-lib/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SoftLinearLayout
3 |
4 |
--------------------------------------------------------------------------------
/softlinearlayout-lib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------