跳到主要内容
漂亮的格式
来源 链接
用户1773603
用户1773603

复制@edwardaa提供的代码我完美地支持实时通讯RTL(实时限值):

公共类GridSpacingItemDecoration扩展了RecyclerView。项目装饰{    私有int spanCount;    私有int间距;    private boolean includeEdge;    private int headerNum;    私有布尔值isRtl=TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())==ViewCompat。布局_方向_ RTL;    public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge,int headerNum){    this.spanCount=span计数;    this.space=间距;    this.includeEdge=包含边缘;    this.headerNum=头编号;    }    @覆盖    public void getItemOffsets(Rect outRect,View视图,RecyclerView父级,RecyclerView.State状态){    int position=parent.getChildAdapterPosition(视图)-headerNum;//项目位置    if(位置>=0){    int column=位置%spanCount;//项目列    如果(isRtl){    column=spanCount-1-列;    }    if(包括Edge){    outRect.left=间距-列*间距/spanCount;//间距-列*((1f/spanCount)*间距)    outRect.right=(column+1)*间距/spanCount;//(列+1)*((1f/spanCount)*间距)    if(位置<spanCount){//上边缘    outRect.top=间距;    }    outRect.bottom=间距;//项目底部    }其他{    outRect.left=列*间距/spanCount;//列*((1f/spanCount)*间距)    outRect.right=间距-(列+1)*间距/spanCount;//间距-(列+1)*((1f/spanCount)*间距)    if(位置>=spanCount){    outRect.top=间距;//项目顶部    }    }    }其他{    outRect.left=0;    outRect.right=0;    outRect.top=0;    outRect.bottom=0;    }}}

}

复制@edwardaa提供的代码我完美地支持实时通讯

公共类GridSpacingItemDecoration扩展了RecyclerView。项目装饰{私有int spanCount;私有int间距;private boolean includeEdge;private int headerNum;私有布尔值isRtl=TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())==ViewCompat。布局_方向_ RTL;public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge,int headerNum){this.spanCount=span计数;this.space=间距;this.includeEdge=包含边缘;this.headerNum=头编号;}@覆盖public void getItemOffsets(Rect outRect,View视图,RecyclerView父级,RecyclerView.State状态){int position=parent.getChildAdapterPosition(视图)-headerNum;//项目位置如果(位置>=0){int column=位置%spanCount;//项目列如果(isRtl){column=spanCount-1列;}if(包括Edge){outRect.left=间距-列*间距/spanCount;//spacing-列*((1f/spanCount)*间距)outRect.right=(列+1)*间距/span计数;//(列+1)*((1f/spanCount)*间距)if(位置<spanCount){//上边缘outRect.top=间距;}outRect.bottom=间距;//项目底部}其他{outRect.left=列*间距/spanCount;//列*((1f/spanCount)*间距)outRect.right=间距-(列+1)*间距/spanCount;//间距-(列+1)*((1f/spanCount)*间距)if(位置>=spanCount){outRect.top=间距;//项目顶部}}}其他{outRect.left=0;outRect.right=0;outRect.top=0;outRect.bottom=0;}}

}

复制@edwardaa提供的代码我完美地支持RTL(实时限值):

公共类GridSpacingItemDecoration扩展了RecyclerView。项目装饰{    私有int spanCount;    私有int间距;    private boolean includeEdge;    private int headerNum;    私有布尔值isRtl=TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())==ViewCompat。布局_方向_ RTL;    public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge,int headerNum){    this.spanCount=span计数;    this.space=间距;    this.includeEdge=包含边缘;    this.headerNum=头编号;    }    @覆盖    public void getItemOffsets(Rect outRect,View视图,RecyclerView父级,RecyclerView.State状态){    int position=parent.getChildAdapterPosition(视图)-headerNum;//项目位置    if(位置>=0){    int column=位置%spanCount;//项目列    如果(isRtl){    column=spanCount-1-列;    }    if(包括Edge){    outRect.left=间距-列*间距/spanCount;//间距-列*((1f/spanCount)*间距)    outRect.right=(column+1)*间距/spanCount;//(列+1)*((1f/spanCount)*间距)    if(位置<spanCount){//上边缘    outRect.top=间距;    }    outRect.bottom=间距;//项目底部    }其他{    outRect.left=列*间距/spanCount;//列*((1f/spanCount)*间距)    outRect.right=间距-(列+1)*间距/spanCount;//间距-(列+1)*((1f/spanCount)*间距)    if(位置>=spanCount){    outRect.top=间距;//项目顶部    }    }    }其他{    outRect.left=0;    outRect.right=0;    outRect.top=0;    outRect.bottom=0;    }}}
来源 链接
兴兴
  • 61
  • 1
  • 5

复制@edwardaa提供的代码我完美地支持rtl

公共类GridSpacingItemDecoration扩展了RecyclerView。项目装饰{私有int spanCount;私有int间距;private boolean includeEdge;private int headerNum;私有布尔值isRtl=TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())==ViewCompat。布局_方向_ RTL;public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge,int headerNum){this.span计数=span计数;this.spacing=间距;this.includeEdge=包含边缘;this.headerNum=头编号;}@覆盖public void getItemOffsets(Rect outRect,View视图,RecyclerView父级,RecyclerView.State状态){int position=parent.getChildAdapterPosition(视图)-headerNum;//项目位置if(位置>=0){int column=位置%spanCount;//项目列如果(isRtl){column=spanCount-1列;}if(包括Edge){outRect.left=间距-列*间距/spanCount;//间距-列*((1f/spanCount)*间距)outRect.right=(column+1)*间距/spanCount;//(列+1)*((1f/spanCount)*间距)if(位置<spanCount){//上边缘outRect.top=间距;}outRect.bottom=间距;//项目底部}其他{outRect.left=列*间距/spanCount;//列*((1f/spanCount)*间距)outRect.right=间距-(列+1)*间距/spanCount;//间距-(列+1)*((1f/spanCount)*间距)if(位置>=spanCount){outRect.top=间距;//项目顶部}}}其他{outRect.left=0;outRect.right=0;outRect.top=0;outRect.bottom=0;}}

}