【问题标题】:Limit the number of characters viewed in textfield in android限制在 android 的文本字段中查看的字符数
【发布时间】:2014-05-10 17:14:33
【问题描述】:

我还是安卓新手,我正在尝试制作一个笔记应用程序

我希望用户能够在标题(文本)中输入任何内容 但只显示几个字符(比如 15 个)后跟 (...)

我尝试搜索此内容,但我发现的唯一内容是如何限制文本大小(我不想这样做,我只想限制查看的内容)

我不想做以下事情:

android:maxLength="10"

所以我的问题是:最好的方法是什么? 还有没有办法在 xml 中或仅在 java 中做到这一点?

任何帮助表示赞赏:)

【问题讨论】:

    标签: java android xml textfield


    【解决方案1】:

    把这个写在你的 textView 中

        android:ellipsize="end"
        android:maxLines="1"
        android:singleLine="true"
    

    如果你想在 textView 中滚动使用这个

        android:scrollHorizontally="true"
    

    http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize

    【讨论】:

      【解决方案2】:

      这不是答案,更多的是评论,但你可以试试android:singleLine = "true"

      source

      【讨论】:

      • 这适用于小字符串,但我有一个(图片然后是文本,然后是日期行),所以当文本很大时,即使只显示一行,图像和文本也会重叠!
      • 试试 android:maxLines = "一些整数"。
      【解决方案3】:

      你只是改变

      android:layout_width="wrap_content"

      在下面使用这个

      android:layout_width="match_parent"

      <LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerVertical="true"
                  android:layout_marginLeft="10dp"
                  android:layout_marginTop="10dp"
                  android:layout_toRightOf="@+id/visitBox"
                  android:orientation="vertical" >
      
                  <TextView
                      android:id="@+id/txvrequestTitle"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:singleLine="true"
                      android:text="Abcdefghighiklmnon"
                      android:textAppearance="?android:attr/textAppearanceLarge"
                      android:textColor="@color/orange_color" />
      
      
              </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-12-07
        • 1970-01-01
        • 2020-03-27
        • 1970-01-01
        • 2012-02-11
        • 1970-01-01
        • 2018-04-09
        相关资源
        最近更新 更多