小编Kaa*_*edi的帖子

Jetpack 撰写 TextField RTL 支持

XML TextField,自动响应RTL文本并右对齐。

\n
    <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" />\n
Run Code Online (Sandbox Code Playgroud)\n

1 * 2

\n

但是,在 Compose 中TextField,它坚持左侧。\n是否有任何方法必须将TextFieldRTL 文本向右对齐,将 LTR 文本向左对齐?

\n

textfield android-jetpack-compose

12
推荐指数
1
解决办法
3156
查看次数

在 ConstraintLayout 中使用 Jetpack Compose 垂直滚动组件

我有一个带有字幕层的播放器层,如下所示:

玩家层

玩家层的父级是并且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)

android android-jetpack-compose

4
推荐指数
1
解决办法
9585
查看次数

Jetpack 撰写对齐和 RTL 文本

在 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 文本并同时对其进行调整?

android-jetpack-compose

3
推荐指数
1
解决办法
3047
查看次数

.hasNext()无法正常工作

    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问题是什么?

java

1
推荐指数
1
解决办法
642
查看次数