2014-02-14 72 views
0

如果我的textview长度太长,我想显示省略号。但由于某种原因,它似乎不起作用。请把它的样子一看图像:ellipsize on textview does not work

enter image description here

这是我的布局代码。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView 
      android:id="@+id/txt1_trans" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:bufferType="spannable" 
      android:layout_marginLeft="10dp" 
      android:singleLine="true" 
      android:ellipsize="end" 
      android:freezesText="true" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:text="My Personal > Bank of America savings" 
      android:textStyle="bold" 
      android:textSize="18sp" 
      android:layout_marginTop="5dp" 
      android:textColor="#000000"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:id="@+id/TextView2" 
    android:layout_height="wrap_content" 
    android:textSize="18sp" 
    android:text="100$" 
    android:textStyle="bold" 
    android:layout_marginRight="20dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@id/txt1_trans" 
    android:layout_alignBottom="@id/txt1_trans"/> 

</RelativeLayout> 

我想在左边(txt1_trans),如果它占用的是右边的TextView的空间来显示省略号TextView的(“TextView2”)占据。请让我知道我做错了什么。

谢谢

回答

0

我发现布局的问题。有关我的布局二号TextView的,我已经设置

alignParentRight =真

和第一的TextView有

宽度= “WRAP_CONTENT”

由于这两个TextView最终都占据了公共空间。为了避免这种情况,我将第一个TextView设置为第二个TextView。这可以确保他们不会尝试在同一个公共空间上写字。这是我正确的布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<TextView 
     android:id="@+id/txt1_trans" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textIsSelectable="true" 
     android:bufferType="spannable" 
     android:layout_marginLeft="10dp" 
     android:singleLine="true" 
     android:ellipsize="end" 
     android:layout_toLeftOf="@+id/TextView2" 
     android:freezesText="true" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:text="My Personal Bank of America savings" 
     android:textStyle="bold" 
     android:textSize="18sp" 
     android:layout_marginTop="5dp" 
     android:textColor="#000000"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:id="@+id/TextView2" 
     android:layout_height="wrap_content" 
     android:textSize="18sp" 
     android:text="100$" 
     android:textStyle="bold" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@id/txt1_trans" 
     android:layout_alignBottom="@id/txt1_trans"/> 
</RelativeLayout> 
0

您不能使用带有wrap_content的ellipsize作为宽度。您需要使用wrap_parent或最好是match_parent,具体取决于您定位的Android版本。

+0

没有这样的属性,如'wrap_parent' - 你的意思'match_parent'或'fill_parent' – ataulm

+0

啊我的道歉FILL_PARENT – Ben