Skip to content

Instantly share code, notes, and snippets.

View xckevin's full-sized avatar

kevin.liu xckevin

  • Alibaba Group
  • Hangzhou China
View GitHub Profile
@xckevin
xckevin / TextFlowLayout.kt
Last active March 3, 2023 07:37
支持View跟随Text的布局组件。如果TextView最后一行足够放下,则跟随TextView最后一行;放不下则换行。支持margin padding调整跟随位置。
class TextFlowLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ViewGroup(context, attrs, defStyleAttr) {
private lateinit var baseTextView: TextView
fun attachTextView(tv: TextView) {
@xckevin
xckevin / RecyclerViewSticky.kt
Created February 3, 2023 03:38
实现RecyclerView的sticky吸顶功能,不通过ItemDecoration实现,解决click等各种event事件问题,解决webview无法渲染问题,但需要外层包一个FrameLayout
import android.graphics.Canvas
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import androidx.recyclerview.widget.StaggeredGridLayoutManager
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software