【问题标题】:How to get EditText of one line which scroll horizontally if text is long如果文本很长,如何获取水平滚动的一行的 EditText
【发布时间】:2018-06-12 06:16:58
【问题描述】:
我已将 maxLines 设置为 1 并将 scrollHorizontally 设置为 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】:
在<HorizontalScrollView> 中使用<EditText>
【解决方案6】:
试试看
android:singleLine="true"