【Kotlin/Android/XML】Viewを傾ける方法!静的や動的に回転させるには?

この記事からわかること
- Android Studio/KotlinでViewを傾ける方法
- XMLのrotation属性の使い方
index
[open]
\ アプリをリリースしました /
環境
- Android Studio:Flamingo
- Kotlin:1.8.20
Viewを傾ける(回転させる)方法
Androidのレイアウトファイル(XML)でViewを傾ける(回転させる)にはandroid:rotation
属性を使用します。左に傾けたい場合は正数を右に傾けたい場合は負数を渡します。
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:rotation="20" />

Kotlinで動的に回転させる
Kotlinで動的に回転させるにはrotation
プロパティにFloat
型で値を渡すだけです。
var text: TextView = findViewById(R.id.textView)
text.rotation = 45.0f // 45度回転させる
まだまだ勉強中ですので間違っている点や至らぬ点がありましたら教えていただけると助かります。
ご覧いただきありがとうございました。