
Jetpack ComposeのPreviewを横画面にする方法

geDem
プレビューを横画面にしたい!
サンプルコード
@Composable
fun SampleView(
orientationText: String
) {
Column(
// ...省略
) {
Text(text = orientationText,
fontSize = 50.sp)
}
}
@Preview(showBackground = true)
@Composable
fun SamplePreview() {
SampleView(orientationText = "縦画面です")
}
解決策
Jetpack Compose のプレビューの引数に、以下を追記します。
(「showSystemUi = true」は使用しないでください。)
@Preview(
// [+追加] //
showBackground = true,
heightDp = 360,
widthDp = 800
)
@Composable
fun SamplePreview() {
SampleView(orientationText = "横画面です")
}
うまく表示されましたね。👏
🙂↕️最後まで読んでいただきありがとうございます🙂↕️