首页 > 解决方案 > 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);

标签: android

解决方案


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>

推荐阅读