简体   繁体   English

TextView 文本超出范围

[英]TextView text going out of bounds

I know this question had been asked a lot but I really searched for an hour and still haven't found the answer.我知道这个问题被问了很多,但我真的搜索了一个小时,仍然没有找到答案。 My TextView in my dialog fragment goes out of bounds, as in the texts inside.我的对话片段中的 TextView 超出了范围,就像里面的文本一样。 在此处输入图像描述

The first textview was supposed to say "Adakah anda......." but it goes out of bounds just like that.第一个 textview 应该说“Adakah anda.......”但它就这样越界了。 I tried changing from wrap to match parent, then fill then weights but still won't change the problem, to autosize libraries (not what I wanted, I wanted to resize the textview, not textsize).我尝试从换行更改为匹配父级,然后填充权重但仍然不会改变问题,自动调整库的大小(不是我想要的,我想调整 textview 的大小,而不是 textsize)。 Please help, tq.请帮忙,tq。

Below is the XML Code下面是 XML 代码

<LinearLayout
        android:layout_width = "match_parent"
        android:orientation="horizontal"
        android:padding="3dp"
        android:layout_marginBottom="30dp"


        android:layout_height = "match_parent">

        <TextView
            android:id = "@+id/tvAdakah"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            android:layout_weight = "1"
            android:text = "@string/adakah_anda_menstruasi_pada_hari_ini" />

        <Switch
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            android:layout_gravity="right|center"
            android:layout_weight="1"
            android:gravity="right|center"/>
    </LinearLayout>

Try using the following,尝试使用以下,

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

for the textView, Maybe it can help对于 textView,也许它可以提供帮助

You can show it in one line and make moving text您可以在一行中显示它并制作移动文本

use xml code like this像这样使用 xml 代码

 <TextView
      android:id = "@+id/tvAdakah"
      android:layout_width = "match_parent"
      android:layout_height = "match_parent"
      android:layout_weight = "1"
      android:singleLine="true"
      android:ellipsize="marquee"
      android:marqueeRepeatLimit="marquee_forever"
      android:text = "@string/adakah_anda_menstruasi_pada_hari_ini" />

In java class you need to set selected this textView在 java class 你需要设置选中这个 textView

TextView view = findViewById(R.id.tvAdakah);
view.setSelected(true);

hope it will helpful希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM