Scrolling TextView value are cut off

删除回忆录丶 提交于 2019-12-10 21:10:48

问题


I have a simple 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>

but text value is cut off with "...", which is the problem?

Dinamically I have a simple activty with scrolling movement:

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);
    }
}

Thank you in advance

SOLUTION: not set setMovementMethod but only setSelected(true) if is necessary. See comments in Yvette answer.


回答1:


I took this out

app:layout_behavior="@string/appbar_scrolling_view_behavior"

and added the features from your previous question 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>




回答2:


Try adding this to your XML layout:

android:maxLines="1"



回答3:


Remove the code: android:singleLine="true" from your xml.



来源:https://stackoverflow.com/questions/33570512/scrolling-textview-value-are-cut-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!