安利一个截长图的工具ScreenShotTools
。git
ScreenShotTools
是一个Android长截图工具。目的是轻松搞定常见的View截图功能。 目前功能有:github
1. ScrollView的截图
2. RecyclerView的截图
3. WebView的截图
4. View的截图
5. 各截图提供拼接头部和尾部功能
复制代码
build.gradle
中添加maven地址(已传入JCenter,本步骤能够忽略)allprojects {
repositories {
..
maven { url 'https://dl.bintray.com/missmydearbear/maven' }
}
}
复制代码
app
目录下的build.gradle
中添加implementation "com.bear:ScreenShotTools:1.0"
复制代码
//1.只截传入的View
fun takeCapture(context: Context, view: View, callBack: IScreenShotCallBack?)
//2.拼接头部图片
fun takeCapture(context: Context, view: View, topBitmap: Bitmap?, callBack: IScreenShotCallBack?)
//3.拼接头部和底部图片
fun takeCapture(
context: Context,
view: View,
topBitmap: Bitmap?,
bottomBitmap: Bitmap?,
callBack: IScreenShotCallBack?
)
//4. 拼接头部和底部图片,且传入图片的宽度
fun takeCapture(
context: Context,
view: View,
topBitmap: Bitmap?,
bottomBitmap: Bitmap?,
width: Int,
callBack: IScreenShotCallBack?
)
复制代码
以RecyclerView为例bash
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_recycler_view)
tv.setOnClickListener {
ScreenShotTools.instance.takeCapture(this, recycler_view, object : IScreenShotCallBack {
override fun onResult(screenBitmap: ScreenBitmap?) {
//todo do your things
}
})
}
loadData()
}
复制代码
gitHub:github.com/MissMyDearB…app