android - 滚动的 TextView 值被截断

标签 android scroll textview horizontal-scrolling marquee

我有一个简单的 TextView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:scrollHorizontally="true"/>

</RelativeLayout>

但是文本值被“...”截断,这是什么问题?

enter image description here

动态地,我有一个带有滚动运动的简单 Activity :

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView t = (TextView) findViewById(R.id.textView);
        t.setMovementMethod(new ScrollingMovementMethod());
        t.setSelected(true);
    }
}

提前致谢

解决方案:不设置 setMovementMethod,但仅在必要时设置 setSelected(true)。请参阅 Yvette 回答中的评论。

最佳答案

我把这个拿出来了

app:layout_behavior="@string/appbar_scrolling_view_behavior"

并添加了您之前问题 HorizontalScrollView cut the text in a TextView and autoscorlling 中的功能

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:foregroundGravity="left"
    android:marqueeRepeatLimit="marquee_forever"
    android:maxLines="1"
    android:text="Title Song and too much information to display in one line."
    android:textAppearance="?android:attr/textAppearanceMedium"/>

</RelativeLayout>

enter image description here

关于android - 滚动的 TextView 值被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33570512/

相关文章:

java - 检查是否在android中启用了GPS

java - 使用服务帐户进行身份验证时,使用 Google Drive API 创建文件到哪个帐户?

ios - 设置新文本后,NSTextView 将停止滚动

android - 没有长触摸,WebView 不会在某些设备上滚动

textview 中的 Android Linkify 电话号码不适用于 nexus 7

android - 如何使用 Intent 将表情符号和文本从 Activity 传递到下一个

android - EditText 自动到最新的字符?

android - 在 Android 中备份 SQLite 数据库

android - java.lang.ClassCastException com.google.android.gms.iid.zzh.onServiceConnected Firebase

javascript - 使用 JQuery/Javascript 进行滚动控制