安利一個截長圖的工具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