android 仿起点文字滚动
时间: 2023-07-28 12:48:26 浏览: 35
你可以使用 Android 中的 TextView 控件来实现仿起点文字滚动的效果。具体实现步骤如下:
1. 在布局文件中添加一个 TextView 控件:
```xml
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"/>
```
2. 在代码中设置 TextView 的属性和内容:
```java
TextView textView = findViewById(R.id.textView);
textView.setText("这是要滚动的文字,这是要滚动的文字,这是要滚动的文字,这是要滚动的文字,这是要滚动的文字,这是要滚动的文字,这是要滚动的文字。");
```
3. 在 Activity 的 onResume() 方法中启动滚动:
```java
@Override
protected void onResume() {
super.onResume();
TextView textView = findViewById(R.id.textView);
textView.setSelected(true);
}
```
这样就可以实现类似起点文字滚动的效果了。需要注意的是,TextView 的 singleLine 属性必须设置为 true,ellipsize 属性必须设置为 marquee,marqueeRepeatLimit 属性可以设置为想要的滚动次数或者 marquee_forever 表示无限滚动。同时,TextView 必须可以获取焦点才能够滚动,因此需要设置 focusable 和 focusableInTouchMode 属性为 true。