|
| 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. |
0 commit comments