【问题标题】:Android textview: text flowing over RHS of screenAndroid textview:文本流过屏幕的RHS
【发布时间】:2021-04-25 02:58:41
【问题描述】:

我创建了一个文本视图(由Android Studio's'新选项卡式活动'helper)并使用存储为原始资源的文本填充它。我允许滚动的视图,除了最后一个字母或两个线路消失的边缘之外,它都是正常的正常工作。两种设备相同,但屏幕尺寸不同。

这是我的资源文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.PlaceholderFragment">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/activity_horizontal_margin"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginEnd="@dimen/activity_horizontal_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:textSize="20sp"
    android:scrollbars = "vertical"
    android:justificationMode="inter_word"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="@+id/constraintLayout"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintTop_creator="1" />
</androidx.constraintlayout.widget.ConstraintLayout>

我已经尝试放大了Marginend(从20到50dp) - 没有效果,也试过Android:Gravity =“中心”,但这使得它更糟糕!

[编辑] 由于建议的答案,观点发生了一些变化。 RHS的边缘出现在RHS下方,因此文本不再消失了屏幕的边缘',但它消失了“背后的边缘”。这有帮助吗?此外,这是一个选项卡式活动(正如我之前提到的)这一事实是否有任何影响?如果我横向滚动查看下一个选项卡,单词的缺失部分仍然不会出现。

【问题讨论】:

    标签: android android-layout textview


    【解决方案1】:

    发生这种情况是因为您的 TextView 不受限制在父母的右边缘。

    您可以通过将以下内容添加到 TextView 来解决此问题

    app:layout_constraintRight_toRightOf="parent"
    

    但您应该避免在布局中使用左右。所以正确的方法是添加

    app:layout_constraintEnd_toEndOf="parent"
    

    还将width 更改为0dp,以便TextView 可以占用约束定义的空间。

    【讨论】:

    • 这让 LHS 失踪了!所以我还添加了app:layout_constraintStart_toStartOf="parent" ,这改善了一点。文本正好在屏幕边缘,但根本没有显示边距。
    • 没有变化,对不起!
    【解决方案2】:

    在您的 textView 上使用 app:layout_constrainedWidth="true",并将开始和结束约束设置为父项。

    【讨论】:

    • 仍然没有真正的区别。我添加了更多信息;查看我最近的编辑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 2011-08-10
    • 2017-12-29
    • 2019-03-19
    • 1970-01-01
    相关资源
    最近更新 更多