当前位置: 首页 > 知识库问答 >
问题:

如何在文本视图末尾显示三个点

松雅健
2023-03-14

我有一个文本视图下的卡片视图,我想如何在文本视图的结尾三个点,当文本足够长的时候。

我尝试在文本视图中添加下面的行,但无法帮助我。

android:singleLine="true"
android:maxLines="1"
android:ellipsize="end"  

截图

 <androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="3dp"
    app:contentPadding="3dp"
    app:cardUseCompatPadding="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/homeBookImage"
            android:layout_width="120dp"
            android:layout_height="150dp"
            android:layout_marginEnd="232dp"
            android:layout_marginRight="232dp"
            android:scaleType="fitXY"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />

         <TextView
            android:id="@+id/homeBookName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:text=""
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toEndOf="@+id/homeBookImage"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0"
            android:singleLine="true"
            android:maxLines="1"
            android:ellipsize="end"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

谢谢

共有1个答案

秦俊友
2023-03-14

您在CardView内部使用了ConstraintLayout,我可以看到您对TextView进行了适当的约束,但是它的宽度是WRAP_Content,这是导致问题的原因。将其设置为0dp,您的Android:ellipsizeAndroid:singleline属性就可以工作了。

试试这个:

<TextView
    ...
    android:layout_width="0dp"
    ... />
 类似资料:
  • 我有一个,我想限制它的字符。实际上,我可以这样做,但我要找的是如何添加三个点(...)在字符串的末尾。这一个显示文本已继续。这是我的XML,但没有点,虽然它限制了我的文本。

  • 问题内容: 与其他语言(例如或)的解释器类似,如何指示在脚本结尾处终止? 跟随命令 带脚本 版画 并等待其他命令。我希望它在文件末尾立即停止。 我正在寻找比脚本结尾更优雅的内容。 问题答案: 在脚本内部,使用jshell命令。这将在脚本末尾退出jshell。 检查此参考https://docs.oracle.com/javase/9​​/jshell/introduction-jshell.htm

  • 我写了一个代码,我在GridView中显示图像,但现在我想在每个图像的底部显示文本。 我想这样展示我的网格: 但是像这样[还想为图像显示文本]: main.xml:

  • 问题内容: 是否可以在 Django视图中显示PDF文件,而不是使用户必须下载它才能看到它? 如果有可能,将如何做? 这是我到目前为止所拥有的 问题答案: 简而言之,如果你有一个PDF文件,并且想通过Django视图输出它,那么你要做的就是将文件内容转储到响应中并以适当的mimetype发送。 你可能可以直接返回响应而无需指定Content-Disposition,但这可以更好地表明你的意图,并且

  • 我需要创建一个组合框,可以有一个按钮在其列表视图的结尾。该列表可以添加或删除项目,当项目数量超过5个时,会显示一个滚动条。此外,当选择一个项目时,该列表视图不会自动关闭。 如何像下面的截图一样添加一个按钮“新项目”? 这是源代码: helloApplication.java 你好控制器.java 您好,查看.fxml

  • 数据显示在logcat中,但不显示在文本视图中。我能做什么 这是我的日志