Skip to content

Commit 2f34cf6

Browse files
author
xubo
committed
first commit
0 parents  commit 2f34cf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2090
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild
9+
bintray.properties
10+
gradle.properties

README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## 1、描述
2+
**CeilingLayout用来控制子View的吸顶联滑,目前支持联滑控件:`NestedScrollView``RecyclerView``SmartRefreshLayout`;只需要在xml里配置需要吸顶子View的位置索引就能自动实现吸顶联滑效果。**
3+
4+
![结合ViewGroup使用例子](https://github.com/pirrip90/CeilingLayout/blob/master/screen/screen2.gif)
5+
6+
## 2、模型图
7+
![模型](https://github.com/pirrip90/CeilingLayout/blob/master/screen/screen1.png)
8+
CeilingLayout``LinearLayout`的子类,使用方法与竖向`LinearLayout`一致。
9+
如模型图所示,`CeilingLayout`竖向排列子View时,吸顶子View之后有且只能再排列一个子View,一般为联动View或包裹住联动View的父容器。
10+
11+
## 3、xml属性
12+
|方法名|参数|描述|
13+
|:---:|:---:|:---:|
14+
| ceiling_childIndex | integer | 吸顶子View的位置索引
15+
16+
## 4、使用
17+
- **xml配置**
18+
```xml
19+
<!-- 子View位置索引为1的子View吸顶 -->
20+
<com.github.xubo.statuslayout.CeilingLayout
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
app:ceiling_childIndex="1">
24+
25+
<View
26+
android:layout_width="match_parent"
27+
android:layout_height="100dp"/>
28+
29+
<TextView
30+
android:layout_width="match_parent"
31+
android:layout_height="100dp"
32+
android:text="我是吸顶View"/>
33+
34+
<android.support.v7.widget.RecyclerView
35+
android:layout_width="match_parent"
36+
android:layout_height="match_parent"/>
37+
38+
</com.github.xubo.statuslayout.StatusLayout>
39+
```
40+
41+
## 5、gradle
42+
add the dependency:
43+
```gradle
44+
dependencies {
45+
   ...
46+
47+
implementation 'com.github.xubo.ceilinglayout:CeilingLayout:1.0.1'
48+
}
49+
```
50+
51+
## 6、注意事项
52+
###1、支持联动View表
53+
- [x] NestedScrollView
54+
- [x] RecyclerView
55+
- [x] SmartRefreshLayout
56+
57+
###2、错误的位置索引配置
58+
> * 不存在的子View位置索引
59+
> * 位置索引为0,索引为0吸顶毫无意义
60+
61+
###3、SmartRefreshLayout使用注意
62+
请使用`CeilingSmartRefreshLayout`代替`SmartRefreshLayout`,否则`SmartRefreshLayout`联动的支持将失效
63+
64+
65+
66+
67+
68+
69+
70+
71+

app/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
app.iml

app/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 28
5+
defaultConfig {
6+
applicationId "com.github.xubo.ceilinglayout.sample"
7+
minSdkVersion 14
8+
targetSdkVersion 28
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 fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation 'com.android.support:appcompat-v7:28.+'
24+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25+
testImplementation 'junit:junit:4.12'
26+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
27+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28+
implementation 'com.android.support:recyclerview-v7:28.+'
29+
implementation project(':ceilinglayout')
30+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.xubo.ceilinglayout.sample;
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+
* Instrumented test, which will execute on an Android device.
14+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
15+
*/
16+
@RunWith(AndroidJUnit4.class)
17+
public class ExampleInstrumentedTest {
18+
@Test
19+
public void useAppContext() {
20+
// Context of the app under test.
21+
Context appContext = InstrumentationRegistry.getTargetContext();
22+
23+
assertEquals("com.github.xubo.ceilinglayout.sample", appContext.getPackageName());
24+
}
25+
}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.github.xubo.ceilinglayout.sample">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.github.xubo.ceilinglayout.sample;
2+
3+
import android.graphics.Color;
4+
import android.support.v4.app.FragmentManager;
5+
import android.support.v4.view.ViewPager;
6+
import android.support.v7.app.ActionBar;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.os.Bundle;
9+
import android.util.DisplayMetrics;
10+
import android.util.Log;
11+
import android.widget.ImageView;
12+
import android.widget.RadioButton;
13+
import android.widget.RadioGroup;
14+
15+
public class MainActivity extends AppCompatActivity {
16+
FragmentManager fragmentManager;
17+
ImageView main_image_iv;
18+
SliderRadioGroup main_srg;
19+
RadioButton main_tab1_rb;
20+
RadioButton main_tab2_rb;
21+
ViewPager main_content_vp;
22+
23+
MyPagerAdapter myPagerAdapter;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_main);
29+
Utils.setColorLight(this, Color.WHITE);
30+
ActionBar actionBar = getSupportActionBar();
31+
if (actionBar != null) {
32+
actionBar.hide();
33+
}
34+
fragmentManager = getSupportFragmentManager();
35+
36+
//id
37+
main_image_iv = findViewById(R.id.main_image_iv);
38+
main_srg = findViewById(R.id.main_srg);
39+
main_tab1_rb = findViewById(R.id.main_tab1_rb);
40+
main_tab2_rb = findViewById(R.id.main_tab2_rb);
41+
main_content_vp = findViewById(R.id.main_content_vp);
42+
43+
main_image_iv.getLayoutParams().height = Utils.getScreenWidth(this) * 540 / 1920;
44+
45+
myPagerAdapter = new MyPagerAdapter(fragmentManager);
46+
main_content_vp.setAdapter(myPagerAdapter);
47+
main_content_vp.setOffscreenPageLimit(2);
48+
main_content_vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
49+
@Override
50+
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
51+
main_srg.move(position, positionOffset);
52+
}
53+
54+
@Override
55+
public void onPageSelected(int position) {
56+
switch (position) {
57+
case 0:
58+
main_tab1_rb.setChecked(true);
59+
break;
60+
case 1:
61+
main_tab2_rb.setChecked(true);
62+
break;
63+
default:
64+
main_tab1_rb.setChecked(true);
65+
break;
66+
}
67+
}
68+
69+
@Override
70+
public void onPageScrollStateChanged(int state) {
71+
72+
}
73+
});
74+
main_srg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
75+
@Override
76+
public void onCheckedChanged(RadioGroup group, int checkedId) {
77+
switch (checkedId) {
78+
case R.id.main_tab1_rb:
79+
main_content_vp.setCurrentItem(0);
80+
break;
81+
case R.id.main_tab2_rb:
82+
main_content_vp.setCurrentItem(1);
83+
break;
84+
default:
85+
main_content_vp.setCurrentItem(0);
86+
break;
87+
}
88+
}
89+
});
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.xubo.ceilinglayout.sample;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.Fragment;
5+
import android.support.v4.app.FragmentManager;
6+
import android.support.v4.app.FragmentPagerAdapter;
7+
8+
/**
9+
* Author:xubo
10+
* Time:2019-03-21
11+
* Description:
12+
*/
13+
public class MyPagerAdapter extends FragmentPagerAdapter {
14+
15+
public MyPagerAdapter(FragmentManager fm) {
16+
super(fm);
17+
}
18+
19+
@Override
20+
public Fragment getItem(int position) {
21+
Fragment fragment;
22+
if (position == 0) {
23+
fragment = new Tab1Fragment();
24+
} else {
25+
fragment = new Tab2Fragment();
26+
}
27+
return fragment;
28+
}
29+
30+
@Override
31+
public int getCount() {
32+
return 2;
33+
}
34+
}

0 commit comments

Comments
 (0)