Skip to content

Commit 86f97ba

Browse files
author
uis
committed
Merge remote-tracking branch 'remotes/origin/dev'
2 parents 0884802 + 154434c commit 86f97ba

26 files changed

Lines changed: 719 additions & 162 deletions

File tree

README-StackLayout.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# StackLayout
2+
**A swipe ViewGroup that supports left and right slide.**
3+
4+
**层叠View支持手势左右滑动,自动轮播,过渡动画**
5+
6+
1.onMeasure通过StackAdapter适配器取到itemView加入到StackLayaout容器
7+
8+
onMeasure() through stackAdapter add view to StackLayout
9+
10+
2.onLayout取到childView按照层叠布局
11+
12+
onLayout() get child view layout stack ui
13+
14+
3.onInterceptTouchEvent处理手势支持子View及Velocity
15+
16+
onInterceptTouchEvent() support child view gesture
17+
18+
4.onTouchEvent处理手势,释放后播放动画平滑过渡
19+
20+
onTouchEvent() swipe animation,when release recover animation
21+
22+
#### Captures
23+
24+
![效果图]()
25+
26+
### Use
27+
implementation 'com.uis:stacklayout:0.3.4'
28+
29+
*Name*| *Descript*|*Value*
30+
-----|--------|---
31+
stackSpace|间距(space)|默认值(default):10dp
32+
stackEdge|边界距离(edge)|默认值(default):10dp
33+
stackZoomX|x方向缩放(x zoom)| 0<x<=1,1表示等间距,默认值(default):1
34+
stackPadX|x方向偏移(x padding)|表示偏移间距,默认值:0
35+
stackPadX|PadX*(Size-1) < Space|PadX优先级高于ZoomX
36+
stackZoomY|y方向缩放(y zoom)| 0<y<=1,1表示和顶层等高度,默认值:0.9
37+
stackLooper|自动轮播(looper)|false/true
38+
stackSize|层叠数量(stack size)|3
39+
stackEdgeModel|层叠位置(stack model)|left/right
40+
41+
```
42+
<?xml version="1.0" encoding="utf-8"?>
43+
<com.uis.stackview.StackLayout xmlns:android="http://schemas.android.com/apk/res/android"
44+
xmlns:stack="http://schemas.android.com/apk/res-auto"
45+
android:id="@+id/stacklayout"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
stack:stackSpace="5dp"
49+
stack:stackEdge="20dp"
50+
stack:stackZoomX="0.1"
51+
stack:stackZoomY="0.1"
52+
stack:stackLooper = "false"
53+
stack:stackSize = "5"
54+
stack:stackEdgeModel = "left">
55+
</com.uis.stackview.StackLayout>
56+
```
57+
58+
```
59+
stackViewLayout.setStackLooper(true);
60+
stackViewLayout.setAdapter(new StackLayout.StackAdapter() {
61+
@Override
62+
public View onCreateView(ViewGroup parent) {
63+
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fresco_layout,null);
64+
}
65+
66+
@Override
67+
public void onBindView(View view, int position) {
68+
SimpleDraweeView dv = view.findViewById(R.id.imageView);
69+
DraweeController controller = Fresco.newDraweeControllerBuilder()
70+
.setUri(Uri.parse(dataList.get(position).getMapImageUrl()))
71+
.setTapToRetryEnabled(true)
72+
.setOldController(dv.getController())
73+
.build();
74+
dv.setController(controller);
75+
}
76+
77+
@Override
78+
public int getItemCount() {
79+
return dataList.size();
80+
}
81+
82+
@Override
83+
public void onItemDisplay(int position) {
84+
Log.e("xx","display = " + position);
85+
}
86+
87+
@Override
88+
public void onItemClicked(int position) {
89+
Log.e("xx","clicked = " + position);
90+
stackViewLayout.setStackLooper(false);
91+
stackViewLayout.setPosition(position+3);
92+
}
93+
});
94+
stackViewLayout.setPosition(10);//指定位置
95+
```
96+
97+
### License
98+
99+
Copyright 2018, uis
100+
101+
Licensed under the Apache License, Version 2.0 (the "License");
102+
you may not use this file except in compliance with the License.
103+
You may obtain a copy of the License at
104+
105+
http://www.apache.org/licenses/LICENSE-2.0
106+
107+
Unless required by applicable law or agreed to in writing, software
108+
distributed under the License is distributed on an "AS IS" BASIS,
109+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
110+
See the License for the specific language governing permissions and
111+
limitations under the License.

README.md

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
# StackViewLayout
2-
**A swipe ViewGroup that supports left and right slide.**
2+
#### Captures
33

4-
**层叠View支持手势左右滑动,自动轮播,过渡动画**
5-
6-
1.onMeasure通过StackAdapter适配器取到itemView加入到StackLayaout容器
7-
8-
onMeasure() through stackAdapter add view to StackLayout
9-
10-
2.onLayout取到childView按照层叠布局
11-
12-
onLayout() get child view layout stack ui
13-
14-
3.onInterceptTouchEvent处理手势支持子View及Velocity
15-
16-
onInterceptTouchEvent() support child view gesture
17-
18-
4.onTouchEvent处理手势,释放后播放动画平滑过渡
19-
20-
onTouchEvent() swipe animation,when release recover animation
21-
22-
### Captures
23-
24-
![效果图](/pic/pic001.jpeg)
25-
![效果图](/pic/demo20.gif)
26-
27-
![尺寸说明](/pic/biaozhu.png)
28-
29-
<li>注释:此图解释参数意义,展示效果不太精确,图片真实宽度为**上层橙色**
4+
![效果图]()
305

316
### Use
32-
implementation 'com.uis:stacklayout:0.3.4'
7+
implementation 'com.uis:stacklayout:0.5.0'
338

349
*Name*| *Descript*|*Value*
3510
-----|--------|---
@@ -42,78 +17,6 @@ stackZoomY|y方向缩放(y zoom)| 0<y<=1,1表示和顶层等高度,默认值
4217
stackLooper|自动轮播(looper)|false/true
4318
stackSize|层叠数量(stack size)|3
4419
stackEdgeModel|层叠位置(stack model)|left/right
45-
46-
```
47-
<?xml version="1.0" encoding="utf-8"?>
48-
<com.uis.stackview.StackLayout xmlns:android="http://schemas.android.com/apk/res/android"
49-
xmlns:stack="http://schemas.android.com/apk/res-auto"
50-
android:id="@+id/stacklayout"
51-
android:layout_width="match_parent"
52-
android:layout_height="wrap_content"
53-
stack:stackSpace="5dp"
54-
stack:stackEdge="20dp"
55-
stack:stackZoomX="0.1"
56-
stack:stackZoomY="0.1"
57-
stack:stackLooper = "false"
58-
stack:stackSize = "5"
59-
stack:stackEdgeModel = "left">
60-
</com.uis.stackview.StackLayout>
61-
```
62-
63-
```
64-
stackViewLayout.setStackLooper(true);
65-
stackViewLayout.setAdapter(new StackLayout.StackAdapter() {
66-
@Override
67-
public View onCreateView(ViewGroup parent) {
68-
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fresco_layout,null);
69-
}
70-
71-
@Override
72-
public void onBindView(View view, int position) {
73-
SimpleDraweeView dv = view.findViewById(R.id.imageView);
74-
DraweeController controller = Fresco.newDraweeControllerBuilder()
75-
.setUri(Uri.parse(dataList.get(position).getMapImageUrl()))
76-
.setTapToRetryEnabled(true)
77-
.setOldController(dv.getController())
78-
.build();
79-
dv.setController(controller);
80-
}
81-
82-
@Override
83-
public int getItemCount() {
84-
return dataList.size();
85-
}
86-
87-
@Override
88-
public void onItemDisplay(int position) {
89-
Log.e("xx","display = " + position);
90-
}
91-
92-
@Override
93-
public void onItemClicked(int position) {
94-
Log.e("xx","clicked = " + position);
95-
stackViewLayout.setStackLooper(false);
96-
stackViewLayout.setPosition(position+3);
97-
}
98-
});
99-
stackViewLayout.setPosition(10);//指定位置
100-
```
101-
102-
### Version
103-
*Version*| *Descript*|*Fixed*
104-
----|----|----
105-
0.0.1|自动轮播,滑动从顶部移除,整体上浮|support auto looper and animation
106-
0.0.2|滑动从顶层加入,整体下沉|fixed child view clicked event
107-
0.1.0|zoomX,zoomY呈等比数列|modify attribute
108-
0.1.1|只有一条数据时|fixed adapter itemSize=1
109-
0.1.2|增加动画、轮播时间设置,获取当前选中位置|add animation,looper time
110-
0.2.0|只有一个元素,不支持轮播和滑动|only one child,can't swipe
111-
0.2.1|减少child层级,见child.measure()|child.measure() opt
112-
0.3.0|增加联动效果(缩放+平移)|support whole animation
113-
0.3.1|联动动画平滑过度|fixed animation smooth
114-
0.3.2|联动动画去抖动及adapter数据更新会多出层|opt animation shake
115-
0.3.3|adapter数据更新ui展示错误|opt adapter changed display
116-
0.3.4|滑动促发item点击事件|fixed item clicked event
11720

11821
### License
11922

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.6.3'
12+
classpath 'com.android.tools.build:gradle:4.0.0'
1313
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
1414
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1515
}
@@ -29,7 +29,7 @@ task clean(type: Delete) {
2929

3030
ext{
3131
androidx = '1.0.0'
32-
compileVer = 28
32+
compileVer = 29
3333
minVer = 15
34-
buildVer = '28.0.3'
34+
buildVer = '29.0.3'
3535
}

demo/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ dependencies {
3030
implementation 'com.google.code.gson:gson:2.8.5'
3131
implementation "androidx.viewpager:viewpager:${androidx}"
3232
implementation 'com.facebook.fresco:fresco:2.2.0'
33+
implementation project(':stackviewlayout')
3334
implementation project(':stacklayout')
3435
}

demo/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:theme="@style/AppTheme"
1818
android:networkSecurityConfig="@xml/network_security_config"
1919
>
20-
<activity android:name=".activity.MainActivity"
20+
<activity android:name="com.uis.stackviewlayout.demo.activity.MainActivity"
2121
android:screenOrientation="portrait"
2222
>
2323
<intent-filter>

demo/src/main/java/com/uis/stackview/demo/activity/MainActivity.java renamed to demo/src/main/java/com/uis/stackviewlayout/demo/activity/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.uis.stackview.demo.activity;
1+
package com.uis.stackviewlayout.demo.activity;
22

33
import android.graphics.Color;
44
import android.os.Build;
@@ -9,7 +9,7 @@
99
import com.facebook.drawee.backends.pipeline.Fresco;
1010
import com.facebook.imagepipeline.core.ImagePipelineConfig;
1111
import com.uis.stackview.demo.R;
12-
import com.uis.stackview.demo.entity.ItemEntity;
12+
import com.uis.stackviewlayout.demo.entity.ItemEntity;
1313
import java.util.List;
1414
import androidx.appcompat.app.AppCompatActivity;
1515
import androidx.recyclerview.widget.LinearLayoutManager;

demo/src/main/java/com/uis/stackview/demo/activity/StackAdapter.java renamed to demo/src/main/java/com/uis/stackviewlayout/demo/activity/StackAdapter.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package com.uis.stackview.demo.activity;
1+
package com.uis.stackviewlayout.demo.activity;
22

33
import android.content.Context;
4+
import android.util.Log;
45
import android.view.LayoutInflater;
56
import android.view.View;
67
import android.view.ViewGroup;
78
import android.widget.ImageView;
89
import com.bumptech.glide.Glide;
9-
import com.facebook.drawee.view.SimpleDraweeView;
10-
import com.uis.stackview.demo.R;
11-
import com.uis.stackview.demo.entity.ItemEntity;
1210
import com.uis.stackview.StackLayout;
11+
import com.uis.stackview.demo.R;
12+
import com.uis.stackviewlayout.demo.entity.ItemEntity;
13+
import com.uis.stackviewlayout.StackViewLayout;
1314
import org.json.JSONArray;
1415
import org.json.JSONObject;
1516
import java.io.InputStream;
@@ -43,7 +44,7 @@ public int getItemViewType(int position) {
4344

4445
@Override
4546
public int getItemCount() {
46-
return 10;
47+
return 2;
4748
}
4849

4950
public static ArrayList<ItemEntity> initDataList(Context context) {
@@ -72,26 +73,27 @@ public static ArrayList<ItemEntity> initDataList(Context context) {
7273
return dataList;
7374
}
7475

75-
public static class ViewHolder {
76-
ImageView imageView;
77-
SimpleDraweeView dv;
78-
}
79-
8076
static class StackVH extends RecyclerView.ViewHolder{
81-
StackLayout stackLayout;
77+
StackViewLayout stackLayout;
8278
List<ItemEntity> stackData = new ArrayList<>();
83-
StackLayout.StackAdapter adapter = new StackLayout.StackAdapter() {
79+
StackViewLayout.StackViewAdapter adapter = new StackViewLayout.StackViewAdapter() {
8480

8581
@Override
8682
public View onCreateView(ViewGroup parent,int viewType) {
8783
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,parent,false);
8884
}
8985

9086
@Override
91-
public void onBindView(View view, int position) {
87+
public void onBindView(View view, final int position) {
9288
ImageView imageView = view.findViewById(R.id.imageView);
9389
try{
9490
Glide.with(view.getContext()).load(stackData.get(position).getMapImageUrl()).into(imageView);
91+
imageView.setOnClickListener(new View.OnClickListener(){
92+
@Override
93+
public void onClick(View v) {
94+
Log.e("xx","onClicked ..."+position);
95+
}
96+
});
9597
}catch (Exception ex){
9698
ex.printStackTrace();
9799
}
@@ -101,25 +103,46 @@ public void onBindView(View view, int position) {
101103
public int getItemCount() {
102104
return stackData.size();
103105
}
106+
};
104107

108+
StackLayout layout;
109+
StackLayout.StackAdapter adapter1 = new StackLayout.StackAdapter() {
105110
@Override
106-
public void onItemDisplay(int position) {
111+
public View onCreateView(ViewGroup parent) {
112+
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,parent,false);
113+
}
107114

115+
@Override
116+
public void onBindView(View view, final int position) {
117+
ImageView imageView = view.findViewById(R.id.imageView);
118+
try{
119+
Glide.with(view.getContext()).load(stackData.get(position).getMapImageUrl()).into(imageView);
120+
}catch (Exception ex){
121+
ex.printStackTrace();
122+
}
123+
}
124+
125+
@Override
126+
public int getItemCount() {
127+
return stackData.size();
108128
}
109129
};
110130

111131
public StackVH(boolean left,ViewGroup parent) {
112132
super(LayoutInflater.from(parent.getContext()).inflate(
113133
left ? R.layout.stack_left : R.layout.stack_right,parent,false));
114-
stackLayout = itemView.findViewById(R.id.stacklayout);
134+
if(left)
135+
stackLayout = itemView.findViewById(R.id.stacklayout);
136+
else
137+
layout = itemView.findViewById(R.id.stacklayout);
115138
}
116139

117140
public void binderVH(final List<ItemEntity> dataList){
118141
stackData = dataList;
119-
if(stackLayout.getAdapter() == null) {
142+
if(stackLayout != null && stackLayout.getAdapter() == null) {
120143
stackLayout.setAdapter(adapter);
121-
}else{
122-
stackLayout.notifyDataChanged();
144+
}else if(layout != null && layout.getAdapter() == null){
145+
layout.setAdapter(adapter1);
123146
}
124147
}
125148
}

0 commit comments

Comments
 (0)