XML TextField,自动响应RTL文本并右对齐。
<com.google.android.material.textfield.TextInputEditText\n android:id="@+id/textview_first"\n android:layout_width="match_parent"\n android:layout_height="wrap_content"\n android:text="\xd8\xb3\xd9\x84\xd8\xa7\xd8\xa7\xd8\xa7\xd8\xa7\xd8\xa7\xd8\xa7\xd9\x85\xd9\x85\xd9\x85\xd9\x85\xd9\x85\xd9\x85\xd9\x85"\n app:layout_constraintBottom_toTopOf="@id/button_first"\n app:layout_constraintEnd_toEndOf="parent"\n app:layout_constraintStart_toStartOf="parent"\n app:layout_constraintTop_toTopOf="parent" />\nRun Code Online (Sandbox Code Playgroud)\n\n但是,在 Compose 中TextField,它坚持左侧。\n是否有任何方法必须将TextFieldRTL 文本向右对齐,将 LTR 文本向左对齐?
我有一个带有字幕层的播放器层,如下所示:
玩家层的父级是并且XML ConstraintLayout有一个ComposeView子级。这ComposeView是我的字幕层。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
app:auto_show="true"
app:controller_layout_id="@layout/layout_exoplayer_control_views"
app:surface_type="surface_view"
app:use_controller="true" />
<androidx.compose.ui.platform.ComposeView
android:id="@+id/subtitle_layout"
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="@color/black_50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
在字幕层中,我Column想添加Modifier.verticalScroll(rememberScrollState())一个滚动到底部内容的内容,例如LazyColumn字幕列表等。
@Composable
fun SubtitleScreen(
newSubtitleList: List<PlayerTrackModel>, viewModel: PlayerViewModel
) {
var items by remember { mutableStateOf(newSubtitleList) }
Column(
modifier = Modifier
.fillMaxWidth()
.background(Color.Black)
.padding(6.dp)
.verticalScroll(rememberScrollState())
) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到了java.lang.IllegalStateException。这是完整的日志:
java.lang.IllegalStateException: Vertically scrollable component was measured …Run Code Online (Sandbox Code Playgroud) 在 jetpack Compose 中,您可以像这样证明Text:
Text(
text = text,
textAlign = TextAlign.Justify
)
Run Code Online (Sandbox Code Playgroud)
如果您想要支持 RTL,可以通过以下方式实现:
Text(
text = text,
textAlign = TextAlign.Right
)
Run Code Online (Sandbox Code Playgroud)
如何Text()在 Jetpack Compose 中支持 RTL 文本并同时对其进行调整?
Scanner scanner = new Scanner(System.in);
// check if the scanner has a token
System.out.println(scanner.hasNext());
// print the rest of the string
System.out.println(scanner.nextLine());
// check if the scanner has a token after printing the line
System.out.println(scanner.hasNext());
Run Code Online (Sandbox Code Playgroud)
当我运行此代码并输入:
你好
在控制台中打印这些:
true
Hi
Run Code Online (Sandbox Code Playgroud)
但从来没有程序结束或打印.false问题是什么?