Skip to content

锯齿带阴影,recyclerView 嵌套 ,recyclerView 同步

Notifications You must be signed in to change notification settings

drchengit/docket_setting

Repository files navigation

docket_setting

需求

写一个可以动态设置展示小票内容的页面。

需求分析(注意只是小票展示和设置,不包括小票的打印)

打印这块有需求,可以联系我,我后面再加上,主要是我太懒了,haha
需求并不难,但是实现起来却相当花时间:(点我白拿

  • 第一点,锯齿带阴影

  • 第二点,票据的宽度切换

  • 第三点,两个布局,都可以滑动,可以动态同步。

白拿点我

难点攻克

锯齿带阴影

想法:

//使用android 自定义View 绘制阴影的api
paint2.setShadowLayer(effect, offset_x, offset_y, Color.parseColor("#33000000"));
//注意关闭硬件加速
  setLayerType(LAYER_TYPE_SOFTWARE, null);

用一个路径圈出一个上下带锯齿、左右是直线的path,画笔上设置阴影,并drawPath()就可以实现锯齿带阴影。

宽度切换

直接设置控件宽度并刷。
宽度变化的同时,控件内容的padding 也是一起改变的,滑动控件中内容的布局要采用wight(比重)来布局,这一点需要讲究。

    /*切换不同宽度模式*/
public void changeWithMode(boolean isFiveEt){
   ViewGroup.LayoutParams params = this.getLayoutParams();
   params.width = isFiveEt?ArmUtils.dip2px(this.getContext(),290)+effect*2:ArmUtils.dip2px(this.getContext(),400)+effect*2;
   this.setLayoutParams(params);
  if(isFiveEt){
      setPadding(effect+ArmUtils.dip2px(this.getContext(),16), ArmUtils.dip2px(this.getContext(),23), effect+ArmUtils.dip2px(this.getContext(),16), ArmUtils.dip2px(this.getContext(),32));
  }else{
      setPadding(effect+ArmUtils.dip2px(this.getContext(),24), ArmUtils.dip2px(this.getContext(),23), effect+ArmUtils.dip2px(this.getContext(),24), ArmUtils.dip2px(this.getContext(),32));
  }
  invalidate();
}

布局滑动并可以动态变化

布局分为展示的滑动区域设置的滑动区域
区域分: 头部尾部
每部分的数据长度不定所以采用recyclerView 公用一个数据源来控,每部数据改变,对面区域的同部位的布局刷新。
区域可滑动,所以每区域使用区域ReyclerView嵌套部位Reyclerview封装度和刷新方面要自由一些。考虑到高效采用局部刷新。
项目: https://github.com/drchengit/docket_setting

结尾

感谢分享: https://www.jianshu.com/p/87f738905e7f
感谢开源: https://blog.csdn.net/iamdingruihaha/article/details/54772834
项目地址: https://github.com/drchengit/docket_setting

我是drchen,一个温润的男子,版权所有,未经允许不得抄袭。

About

锯齿带阴影,recyclerView 嵌套 ,recyclerView 同步

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages