【问题标题】:How to get EditText of one line which scroll horizontally if text is long如果文本很长,如何获取水平滚动的一行的 EditText
【发布时间】:2018-06-12 06:16:58
【问题描述】:

我已将 maxLines 设置为 1 并将 scrollHorizo​​ntally 设置为 True,但它不起作用。它提供垂直滚动的多行 EditText。

       <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Work"
            android:maxLines="1"
            android:lines="1"
            android:scrollHorizontally="true"
            android:textSize="18sp"
            android:padding="4dp"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="48dp"/>

【问题讨论】:

    标签: android android-layout android-edittext


    【解决方案1】:

    尝试添加此属性:

    singleLine="true"
    

    【讨论】:

      【解决方案2】:

      包装EditTextin HorizontalScrollView

      <HorizontalScrollView
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
      
              <EditText
                  android:layout_width="wrap_content"
                  android:maxLines="1"
                  android:layout_height="wrap_content" />
      </HorizontalScrollView>
      

      【讨论】:

        【解决方案3】:

        您必须添加singleLine="true"

        <EditText
                android:id="@+id/editTextHorizontalScroll"
                android:textSize="18sp"
                android:padding="4dp"
                android:layout_marginStart="32dp"
                android:layout_marginEnd="48dp"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Work" />
        

        【讨论】:

          【解决方案4】:

          我看到你有一个解决方案,但我向你展示了另一种方式,通过这种方式,如果文本视图太长,你的文本视图可以自动滑动,非常有趣。

                           <TextView
                              android:id="@+id/text_view"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:ellipsize="marquee"
                              android:marqueeRepeatLimit="marquee_forever"
                              android:scrollHorizontally="true"
                              android:singleLine="true"
                              android:text="marquee_forever marquee_forever marquee_forever marquee_forever"
                              android:textColor="@color/white"
                              android:textSize="12dp"
                              android:textStyle="bold"
                              />
          

          【讨论】:

            【解决方案5】:

            &lt;HorizontalScrollView&gt; 中使用&lt;EditText&gt;

            【讨论】:

              【解决方案6】:

              试试看

              android:singleLine="true" 
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2013-10-09
                • 2021-07-02
                • 1970-01-01
                • 2012-06-03
                • 2015-11-28
                • 1970-01-01
                • 1970-01-01
                • 2013-12-13
                相关资源
                最近更新 更多