Skip to content

Commit 7eab309

Browse files
committed
xfermode基础效果、图片处理效果
1 parent 5a8c90c commit 7eab309

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

app/src/main/kotlin/org/ninetripods/mq/study/fragment/XFerModeIMGFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class XFerModeIMGFragment : BaseFragment() {
3737
}
3838

3939
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
40-
recyclerView.layoutManager = GridLayoutManager(context, 2)
40+
recyclerView.layoutManager = GridLayoutManager(context, 3)
4141
context?.let { recyclerView.createDivider(it, 5.dp2px().toFloat()) }
4242

4343
// 准备数据

app/src/main/kotlin/org/ninetripods/mq/study/util/DrawableUtil.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.ninetripods.mq.study.util
22

33
import android.content.Context
44
import android.graphics.Color
5+
import android.graphics.drawable.Drawable
56
import android.graphics.drawable.ShapeDrawable
67
import android.graphics.drawable.shapes.RectShape
78
import androidx.recyclerview.widget.DividerItemDecoration
@@ -11,18 +12,24 @@ import androidx.recyclerview.widget.RecyclerView
1112
* @param context 上下文,用于转换 dp 到 px
1213
* @param heightDp 分割线的高度(单位:dp)
1314
* @param color 分割线的颜色
15+
* @param drawable 传入的drawable
1416
*/
15-
fun RecyclerView.createDivider(context: Context, heightDp: Float = 0.5f, color: Int = Color.TRANSPARENT) {
16-
//创建动态分割线 Drawable
17-
val shapeDrawable = ShapeDrawable(RectShape()).apply {
17+
fun RecyclerView.createDivider(
18+
context: Context,
19+
heightDp: Float = 0.5f,
20+
color: Int = Color.TRANSPARENT,
21+
drawable: Drawable? = null
22+
) {
23+
//优先使用传入的drawable,没有传入的话创建动态分割线Drawable
24+
val shapeDrawable = drawable ?: ShapeDrawable(RectShape()).apply {
1825
// 设置分割线的高度
1926
intrinsicHeight = (heightDp * context.resources.displayMetrics.density + 0.5f).toInt() // 将 dp 转换为 px
2027
// 设置分割线的颜色
2128
paint.color = color
2229
}
2330
//将动态分割线添加到 RecyclerView
2431
val dividerItemDecoration = DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply {
25-
setDrawable(shapeDrawable)
32+
setDrawable(shapeDrawable)
2633
}
2734
this.addItemDecoration(dividerItemDecoration)
2835
}

app/src/main/kotlin/org/ninetripods/mq/study/widget/XfermodeImgView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class XfermodeImgView @JvmOverloads constructor(
5858
super.onDraw(canvas)
5959
if (!::imageBitmap.isInitialized) return
6060

61-
canvas.drawRect(mRectF, mStrokePaint) //绘制边框
61+
//canvas.drawRect(mRectF, mStrokePaint) //绘制边框
6262

6363
if (mCurShape == SHAPE_ORIGIN) {
6464
//展示原图

0 commit comments

Comments
 (0)