【问题标题】:Meaning of the ellipsise options省略号选项的含义
【发布时间】:2012-02-03 02:43:05
【问题描述】:

我看到android:ellipsize 有 4 个不同的值:

none,start,mid,endmarquee

分别设置的意义和作用是什么?

【问题讨论】:

标签: android ellipsis


【解决方案1】:

查看下图了解android:ellipsize 的工作原理

我用过以下xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:maxLines="4" 
        android:ellipsize="none" 
        android:singleLine="false" 
        android:text="Hi make this a very long string that wraps at least 4 lines, seriously make it really really long so it gets cut off at the fourth line not joke.  Just do it!" 
        android:layout_marginBottom="25dip" />

    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:maxLines="4" 
        android:ellipsize="start" 
        android:singleLine="false" 
        android:text="Hi make this a very long string that wraps at least 4 lines, seriously make it really really long so it gets cut off at the fourth line not joke.  Just do it!" 
        android:layout_marginBottom="25dip" />

    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:maxLines="4" 
        android:ellipsize="middle" 
        android:singleLine="false" 
        android:text="Hi make this a very long string that wraps at least 4 lines, seriously make it really really long so it gets cut off at the fourth line not joke.  Just do it!" 
        android:layout_marginBottom="25dip" />

    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:maxLines="4" 
        android:ellipsize="end" 
        android:singleLine="false" 
        android:text="Hi make this a very long string that wraps at least 4 lines, seriously make it really really long so it gets cut off at the fourth line not joke.  Just do it!" 
        android:layout_marginBottom="25dip" />

    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:maxLines="4" 
        android:ellipsize="marquee" 
        android:text="Hi make this a very long string that wraps at least 4 lines, seriously make it really really long so it gets cut off at the fourth line not joke.  Just do it!" />

</LinearLayout>

【讨论】:

  • 无法更好地解释 .. 所以 marquee 和 end 具有相同的效果。我在我的 textview marquee 中使用它并没有出现在设备上,只是尝试使用 end 和它的到来进行测试。对此行为的任何评论。非常感谢您
  • 你设置android:maxLines="4",TextViews有2行。为什么?
  • Middle 和 start ellipsize 不适用于 Honeycomb 及更高版本的 Android。
  • @Mike 这不一定是真的(至少在 2016 年 1 月运行 Android L 的 Nexus 5 上)
  • @png 的情况下,需要设置singleLine=true。有趣的是,当您组合 ellipsize=marqueesingleLine=true 时,您不会收到弃用警告。
猜你喜欢
  • 2019-06-28
  • 1970-01-01
  • 1970-01-01
  • 2020-10-20
  • 2015-07-08
  • 2019-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多