Android TextView 跑马灯不工作

标签 android android-layout textview marquee

选取框不适用于我的 TextView 请检查以下代码

TextView

XML 代码

                          <TextView
                            android:id="@+id/mtextcash"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="30dp"
                            android:ellipsize="marquee"
                            android:fadingEdge="horizontal"
                            android:gravity="center"
                            android:marqueeRepeatLimit="marquee_forever"
                            android:maxLength="5"
                            android:scrollHorizontally="true"
                            android:scrollbars="horizontal"
                            android:singleLine="true"
                            android:text="Simple application that shows how to use marquee, with a long text"
                            android:textColor="@color/white"
                            android:textColorHint="@color/white"
                            android:textSize="25dp" />

在 Activity OnCreate 中

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
inputAvailableCash.setSelected(true);

提前致谢

最佳答案

由于文本很长,而且您的代码只有在您将文本写成单行时才能正常工作。要么添加

 android:singleline="true" 

在 xml 中或将您的 java 代码更改为。

  TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash);
        inputAvailableCash.setSelected(true);
         inputAvailableCash.setSingleLine(true);

这肯定对你有用。

关于Android TextView 跑马灯不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605878/

相关文章:

android - AutoResizeTextView 未按预期工作

带有提示和图像的 Android 可点击 TextView 可启动搜索对话框并显示所选结果

android - GLSurfaceView - 如何制作半透明背景

Android 是否可以从服务中获取 Activity 偏好值?

安卓 list .xml;无法包含外部库

Android:如何设置布局的文本大小?

java - 初始屏幕填满整个智能手机屏幕,但不裁剪

java - DrawerLayout 和 NavigationView - 未找到属性 'menu'

Android - Textview 在状态改变时改变颜色

java - 将网络位置保存为 .txt 文件(不使用 GPS)