无论我给出什么参数,我都有一个溢出的textview

时间:2013-03-16 16:31:17

标签: android

这是一个文本视图,可能在其旁边有长文本。它流过并将一半的评级栏推离屏幕。

如何剪切文本而不关闭评级栏?

<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>

4 个答案:

答案 0 :(得分:0)

你可以检查字符串的长度,如果它大于设定的长度,并在字符串末尾做...之类的事情

但您要将textview设置为wrap_context,您也可以将其设置为宽度,以便不会更改

答案 1 :(得分:0)

您可以在文字视图中使用以下属性

android:layout_toLeftOf="@id/myRatingBar" 

您还可以在xml

中为textview指定特定宽度
  android:layout_width="wrap_content"

并且您还可以使用以下属性来限制文本视图的长度

android:maxLength=""

答案 2 :(得分:0)

使用android:maxLines="1"。如果文本很长,这将删除TextView中的文本,并且不会关闭评级。

答案 3 :(得分:0)

由于您已将android:layout_weight="1"设置为两个视图,因此我认为您可以执行android:layout_width="match_parent"

这将使两个视图具有相同的宽度,即父级宽度的一半。或者您可以根据您想要的任何值修改权重字段。