2017-07-14 6 views
0

enter image description hereAndroid XML:TextViewに別の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>

答えて

0

あなたのTextViewがellipsizedされているかどうかを確認することができます

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 
} 

別の周りに1つのTextViewを流れるように、あなたはthis質問

を使用することができます
関連する問題