简体   繁体   English

我有一个textview不管我给它什么参数都溢出

[英]I have an textview that overflows no matter what parameters I give it

It's a textview that could possibly have long text in side it. 这是一个textview,可能在其旁边有长文本。 it over flows and pushes half of ratings bar off the screen. 它溢出,并将一半的额定值栏推离屏幕。

How can I make it cut the text and not push the ratingsbar off? 如何使它剪切文本而不关闭等级栏?

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp"
        android:weightSum="2" >

        <TextView
            android:id="@+id/rest_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:paddingLeft="3dp"
            android:singleLine="true"
            android:text="long text goes goes here long text goes goes here long text goes goes here"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <RatingBar
            android:id="@+id/myRatingBar"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:numStars="5" />
    </LinearLayout>

you could check the length of the string and if it is greater than a set length and do something like ... at the end of the string 您可以检查字符串的长度,如果它大于设置的长度,则在字符串末尾执行类似...的操作

but you are setting the textview to wrap_context you could also just make it a hard width so it wont change 但是您将textview设置为wrap_context ,也可以将其设置为硬宽度,这样就不会改变

you can use the following attribute in your text view 您可以在文本视图中使用以下属性

android:layout_toLeftOf="@id/myRatingBar" 

you can also give a specific width to your textview in xml 您还可以为xml中的textview提供特定的宽度

  android:layout_width="wrap_content"

and also you can use the following attribute to limit the length of text view 并且您还可以使用以下属性来限制文本视图的长度

android:maxLength=""

Use android:maxLines="1" . 使用android:maxLines="1" This will cut the text in the TextView if it is long and will not push the Ratings off. 如果文本很长,这将剪切TextView中的文本,并且不会推迟“等级”。

Since you have set the android:layout_weight="1" to both views, then I think you can do android:layout_width="match_parent" 由于您已将android:layout_weight="1"为两个视图,所以我认为您可以执行android:layout_width="match_parent"

This will make both views have the same width which is half the parent's width. 这将使两个视图具有相同的宽度,该宽度是父视图的宽度的一半。 Or you could modify the weight field according to whatever value you want. 或者,您可以根据所需的任何值修改权重字段。

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

相关问题 TextView不保留我给它的值 - TextView not retaining the value I give it 无论我尝试以何种方式更改其内容,TextView Id 都会一直调用 null - TextView Id keeps calling on null no matter what way I try to change its content 我旋转的 TextView 被切断了。 我必须做什么? - My rotated TextView is cut off. What i have to do? 我必须在textview上一一显示所有名称请给出解决方案 - I have to display all names one by one on textview please give solution 为什么我有TextView页边距? - Why i have in TextView margin? 我在检查textview时遇到问题 - i have an issue with checked textview 我该怎么做才能使无论文本多长时间都将具有相同的起始对齐方式? - What can I do so that no matter how long the text all will have same starting alignment? 我曾尝试添加一个Facebook登录按钮,但无论如何,按下它后出现错误 - I have tried to add a Facebook login button, but no matter what, after pressing it there's an error 我有一个ListView,其中每一行都包含一个EditText字段和textview,我在Edittext中键入的内容我想在textview中看到什么? - I have a ListView, where each row contains an EditText field and textview, what ever i typed in the Edittext i want to see in the textview? 无论我做什么,DividerItemDecoration 都不起作用 - DividerItemDecoration will not work no matter what I do
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM