问题描述
当我使用的TextView
与 SINGLELINE =真正的
和 ellipsize =结束
(我的前的TextView)效果很好的
when I am using TextView
with singleLine="true"
and ellipsize="end"
(my top TextView),it works well
但是在另一 的TextView
有我的底部 3行更多然后1号线(在我的情况的TextView
),行=3和MAXLINES =3和ellipsize =结束,
无法正常工作。
but in another TextView
having more then 1 lines (in my case 3 lines in my bottom TextView
),lines="3" and maxLines="3" and ellipsize="end",
doesn't work properly.
当我不把 ellipsize =结束
在tvDesc,它显示3行,这是确定。这里是code:XML:
When I DON'T put ellipsize="end"
in tvDesc, it shows 3 line, which is OK.Here is code : XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imgv"
android:layout_width="65dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/img1"
android:scaleType="fitXY" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imgv"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="Title testing line number and ellipsize at end"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end" <--- WORKS WELL
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tvDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTitle"
android:layout_toRightOf="@+id/imgv"
android:layout_alignBottom="@+id/imgv"
android:layout_alignParentRight="true"
android:textSize="14dp"
android:lines="3"
android:maxLines="3"
<---------- WITHOUT ellipsize
android:text="I wanna this textview of having 3 lines and ellipsize at END and at this time I am Testing for it. This TextView shows 3 lines WITHOUT ellipsize property, but shows only 2 Lines when ELLIPSIZE property is setted"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
以上code显示的TextView tvDesc有3条线路和无Ellipsize 以下是图像:
但是,我想ellipsize,所以我使用了跟随着code :XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imgv"
android:layout_width="65dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/img1"
android:scaleType="fitXY" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imgv"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="Title testing line number and ellipsize at end"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tvDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvTitle"
android:layout_toRightOf="@+id/imgv"
android:layout_alignBottom="@+id/imgv"
android:layout_alignParentRight="true"
android:textSize="14dp"
android:lines="3"
android:maxLines="3"
android:ellipsize="end" <------ WITH ELLIPSIZE
android:text="I wanna this textview of having 3 lines and ellipsize at END and at this time I am Testing for it. This TextView shows 3 lines WITHOUT ellipsize property, but shows only 2 Lines when ELLIPSIZE property is setted"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
这都说明TextView的tvDesc只有2线和Ellipsize
这是不正确的UI dezired,作为跟随着:
which is not properly dezired UI, as Followin:
我想在TextView中tvDesc 3线,ellipsize
谁能帮助我?
推荐答案
这是迄今为止我发现,我目前使用的部署最简单的解决方案。让我知道如果你需要任何其他帮助!
This is by far the simplest solution I've found and am currently using in deployment. Let me know if you need any other assistance!
呵呵,记得删除安卓ellipsize
标签中的XML,因为您将使用底部code自动ellipsize在3行的末尾。
Oh and remember to remove the android:ellipsize
tag in your XML since you will be using the bottom code to automatically ellipsize at the end of 3 lines.
TextView snippet;
snippet.setText("loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor loren ipsum dolor ")
ViewTreeObserver vto = this.snippet.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ViewTreeObserver obs = snippet.getViewTreeObserver();
obs.removeGlobalOnLayoutListener(this);
if (snippet.getLineCount() > 3) {
int lineEndIndex = snippet.getLayout().getLineEnd(2);
String text = snippet.getText().subSequence(0, lineEndIndex - 3) + "...";
snippet.setText(text);
}
}
});
这篇关于在TextView中设置Ellipsize减少由一个(而不是只ellipsizing最后)所示线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!