我有身体代码:
<TextView
android:maxLines="3"
android:ellipsize="end"
android:textColor="@color/text_grey"
android:textSize="@dimen/text_size_normal"
android:textAppearance="@style/FontPath.Light"
android:id="@+id/tv_content_notification"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
我使用的是android:ellipsize="end"
,但在运行时会显示以下内容:
发布于 2016-10-27 04:10:26
试着这样做,它会工作的
android:maxLines="3"
android:ellipsize="end"
android:singleLine="false"
或
尝试使用ViewTreeObserver
,您需要计算适合文本视图的线与其高度,然后设置最大长度
ViewTreeObserver observer = textView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int maxLines = (int) textView.getHeight()
/ textView.getLineHeight();
textView.setMaxLines(maxLines);
textView.getViewTreeObserver().removeGlobalOnLayoutListener(
this);
}
});
https://stackoverflow.com/questions/40275926
复制相似问题