android - Android textview 可水平滚动
问题描述
我想滚动文本,但它不滚动,我使用了这段代码,但它不起作用。我尝试了其他代码但仍然无法正常工作
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Some text "
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
这在适配器类
if (tv.getText().toString().length() > tv.getMaxLines())
tv.setSelected(true);
解决方案
Try this, hope it may helps you.
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view will work now"/>
</HorizontalScrollView>
推荐阅读
- python - 为什么我的号码中的数字分开打印而不是一起打印?
- google-cloud-platform - 如何知道 GCE 实例在控制台中使用的存储类型
- reactjs - 如何在 React 中指定多个宽度
- python - 使用“烧瓶运行”获取 ImportError
- javascript - 如何关闭未在数组中选择的 Div?Shopify 中的 Javascript
- windows - 下载服务后在 Windows 上设置 SNMP
- php - PHP数组爆炸作业
- generics - 在 HashMap 中存储特征的不同实现
- c++ - Range-v3:为什么这里需要ranges::to_vector?
- typescript - 即使配置了 @ValidateNested 和 @Type,NestJS ValidationPipe() 也不处理嵌套对象