繁体   English   中英

Android XML:当TextView包含另一个TextView时使用ellipsize吗?

[英]Android XML: Using ellipsize when a TextView contains another TextView?

在此处输入图片说明

如设计中所示,我需要一个TextView,当它遇到另一个TextView时它会变椭圆(现在暂时忘记小箭头图像)。 扩展按钮在底部,而容器的最大高度是固定的。

我正在发布暂时无法使用的代码,因为TextViews重叠了。 请提出更改建议。

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/expandable" tools:context="akshay.expandableview.MainActivity" android:layout_width="208dp" android:layout_height="wrap_content" android:maxHeight="204dp" android:background="#abcdef" android:padding="8dp"> <TextView android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16dp" android:lineSpacingMultiplier="1.2" android:textColor="#000" android:ellipsize="end" android:maxLines="8" android:text="It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)."/> <TextView android:id="@+id/expand_btn" android:layout_width="70dp" android:layout_height="20dp" android:background="#fedcba" android:layout_alignBottom="@+id/content" android:layout_alignParentRight="true" android:text="Expand" android:gravity="center"/> </RelativeLayout> 

您可以检查TextView是否为椭圆形:

boolean isElipsized = false;
Layout layout = textview1.getLayout();
if(layout != null) {
    int lines = layout.getLineCount();
    if(lines > 0) {
        int ellipsisCount = layout.getEllipsisCount(lines-1);
        if (ellipsisCount > 0) {
            isElipsized = true;
        } 
    } 
}

if(isElipsized) {
    //show the "show more" view
}

要将一个TextView环绕另一个,可以使用以下问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM