Skip to content

Instantly share code, notes, and snippets.

@Kenny50
Kenny50 / MainActivity.kt
Created July 2, 2023 05:46
Update webview rotate with android animate
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
@RequiresApi(Build.VERSION_CODES.R)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
@Kenny50
Kenny50 / AndroidAnimateRotateScreen.kt
Created July 2, 2023 03:20
Rotate solution for device doesn't have gyroscope, wouldn't be affect by hardware or Android OS version, but need update surfaceview to textureview, ex. exoplayer, mapbox
// MainActivity.kt
@RequiresApi(Build.VERSION_CODES.R)
private fun rotateScreen() {
binding.main.apply {
val bounds = windowManager.currentWindowMetrics.bounds
val viewHeightAfterRotate = bounds.right
val viewWidthAfterRotate = bounds.bottom
updateLayoutParams {
this.width = viewWidthAfterRotate
this.height = viewHeightAfterRotate