ellipsize上的TextView不工作 [英] ellipsize on textview doesnt work
问题描述
我要显示省略号如果我的TextView的长度太长。但由于某些原因,它似乎没有工作。请把它的样子来看看图片:
I want to display ellipsis if my textview length is too long. But for some reason, it doesnt seem to work. Please take a look at the image on how it looks like:
下面是我的布局code。
Here is my layout code.
<?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)占用。请让我知道我做错了。
I want the textView on the left (txt1_trans) to display ellipsis if it takes up the space that textview on the right ("TextView2") occupies. Please let me know what I am doing wrong.
感谢
推荐答案
我发现与布局的问题。有关我的布局二号TextView的,我已经设置
I found the problem with the layout. For the 2nd TextView on my layout, I have set
alignParentRight = TRUE
alignParentRight = true
。和第一TextView的有
. And the 1st TextView has
WIDTH =WRAP_CONTENT
width = "wrap_content"
。正因为如此,无论是这些TextViews最终占用公共空间。为了避免这种情况,我将第一个TextView的to_LeftOf第二TextView的。这确保了它们不要试图在相同的公共空间写入。这是我正确的布局:
. Because of this, both these TextViews end up taking up common space. In order to avoid that, I set the first TextView to_LeftOf 2nd TextView . This ensures that they dont try to write on the same common space . Here is my correct layout :
<?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>
这篇关于ellipsize上的TextView不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!