Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
d6e641b0
Commit
d6e641b0
authored
Feb 28, 2023
by
赵鹏翔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
81c5d3fb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
43 deletions
+40
-43
Divider.java
app/src/main/java/com/miya/fastcashier/widget/Divider.java
+0
-43
Divider.kt
app/src/main/java/com/miya/fastcashier/widget/Divider.kt
+40
-0
No files found.
app/src/main/java/com/miya/fastcashier/widget/Divider.java
deleted
100644 → 0
View file @
81c5d3fb
package
com
.
miya
.
fastcashier
.
widget
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.view.View
;
import
androidx.recyclerview.widget.RecyclerView
;
/**
* 通用的RecyclerDivider
*/
public
class
Divider
extends
RecyclerView
.
ItemDecoration
{
private
Paint
paint
;
private
int
divideWidth
;
public
Divider
(
int
divideWidth
,
int
color
)
{
super
();
this
.
paint
=
new
Paint
();
paint
.
setAntiAlias
(
true
);
paint
.
setColor
(
color
);
this
.
divideWidth
=
divideWidth
;
}
@Override
public
void
onDraw
(
Canvas
c
,
RecyclerView
parent
,
RecyclerView
.
State
state
)
{
int
left
=
parent
.
getPaddingStart
();
int
right
=
parent
.
getMeasuredWidth
()
-
parent
.
getPaddingEnd
();
View
child
;
int
childPosition
;
int
validChildCount
=
parent
.
getChildCount
();
for
(
int
i
=
0
;
i
<
validChildCount
;
i
++)
{
child
=
parent
.
getChildAt
(
i
);
childPosition
=
parent
.
getChildAdapterPosition
(
child
);
if
(
childPosition
==
validChildCount
-
1
)
{
break
;
}
RecyclerView
.
LayoutParams
layoutParams
=
(
RecyclerView
.
LayoutParams
)
child
.
getLayoutParams
();
int
top
=
child
.
getBottom
()
+
layoutParams
.
bottomMargin
;
int
bottom
=
top
+
divideWidth
;
c
.
drawRect
(
left
,
top
,
right
,
bottom
,
paint
);
}
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/widget/Divider.kt
0 → 100644
View file @
d6e641b0
package
com.miya.fastcashier.widget
import
android.graphics.Canvas
import
android.graphics.Paint
import
android.view.View
import
androidx.recyclerview.widget.RecyclerView.ItemDecoration
import
androidx.recyclerview.widget.RecyclerView
/**
* 通用的RecyclerDivider
*/
class
Divider
(
divideWidth
:
Int
,
color
:
Int
)
:
ItemDecoration
()
{
private
val
paint
:
Paint
private
val
divideWidth
:
Int
override
fun
onDraw
(
c
:
Canvas
,
parent
:
RecyclerView
,
state
:
RecyclerView
.
State
)
{
val
left
=
parent
.
paddingStart
val
right
=
parent
.
measuredWidth
-
parent
.
paddingEnd
var
child
:
View
var
childPosition
:
Int
val
validChildCount
=
parent
.
childCount
for
(
i
in
0
until
validChildCount
)
{
child
=
parent
.
getChildAt
(
i
)
childPosition
=
parent
.
getChildAdapterPosition
(
child
)
if
(
childPosition
==
validChildCount
-
1
)
{
break
}
val
layoutParams
=
child
.
layoutParams
as
RecyclerView
.
LayoutParams
val
top
=
child
.
bottom
+
layoutParams
.
bottomMargin
val
bottom
=
top
+
divideWidth
c
.
drawRect
(
left
.
toFloat
(),
top
.
toFloat
(),
right
.
toFloat
(),
bottom
.
toFloat
(),
paint
)
}
}
init
{
paint
=
Paint
()
paint
.
isAntiAlias
=
true
paint
.
color
=
color
this
.
divideWidth
=
divideWidth
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment