我有一个简单的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>
但文字值被&#34; ...&#34; 切断,这是问题所在?
Dinamically我有一个简单的滚动动作:
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答案中的评论。
答案 0 :(得分:2)
我把它拿出来
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>
答案 1 :(得分:0)
尝试将其添加到XML布局中:
android:maxLines="1"
答案 2 :(得分:0)
从xml中删除代码:android:singleLine="true"
。