Android TextView的垂直滚动效果
2017-03-24 11:30
513 查看
在TextView中,如果文本很长而TextView的高度有限,那可能就需要实现垂直滚动显示文本的效果了。
先上效果图
![](https://oscdn.geek-share.com/Uploads/Images/Content/202009/03/4a326d1ffa995eb83a9c284954b84a5c)
XML布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/scrolltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ffff"
android:maxLines="6"
android:padding="5dp"
android:text="一旦韩国部署“萨德”系统,可能受到影响的解放军导弹主要是4种公路机动的中程和远程导弹。此外,中国的反舰弹道导弹东风-21D、潜射导弹巨浪-2等都可能被“萨德”拦截。事实上,萨德生产商洛克希德·马丁公司正投入精力发展一款拦截高度更大的改进型萨德,目的是拦截极超音速滑翔器,包括中国研制的WU-14。这才是需要更加警惕的!"
android:textSize="16sp" />
</RelativeLayout>
Activity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView scrolltext = (TextView) findViewById(R.id.scrolltext);
//关键代码
scrolltext.setMovementMethod(ScrollingMovementMethod.getInstance());
}
}
先上效果图
XML布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/scrolltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ffff"
android:maxLines="6"
android:padding="5dp"
android:text="一旦韩国部署“萨德”系统,可能受到影响的解放军导弹主要是4种公路机动的中程和远程导弹。此外,中国的反舰弹道导弹东风-21D、潜射导弹巨浪-2等都可能被“萨德”拦截。事实上,萨德生产商洛克希德·马丁公司正投入精力发展一款拦截高度更大的改进型萨德,目的是拦截极超音速滑翔器,包括中国研制的WU-14。这才是需要更加警惕的!"
android:textSize="16sp" />
</RelativeLayout>
Activity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView scrolltext = (TextView) findViewById(R.id.scrolltext);
//关键代码
scrolltext.setMovementMethod(ScrollingMovementMethod.getInstance());
}
}
相关文章推荐
- Android中TextView实现垂直滚动和上下滚动效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android TextView实现垂直滚动的跑马灯效果
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android TextView的垂直滚动效果
- Android中TextView实现垂直滚动(轮换效果,非跑马灯)
- Android:TextView的垂直滚动效果,和上下滚动效果
- Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
- Android TextView实现垂直滚动效果的方法
- android中TextView中如何设置水平滚动效果
- android TextView 垂直自动滚动
- Android安卓的TextView内容超长的时候,垂直滚动
- android中TextView中如何设置水平滚动效果
- android TextView 垂直自动滚动字幕实现
- android TextView 垂直自动滚动字幕实现
- Android TextView 垂直自动滚动
- android自定义View-垂直滚动的TextView
- 亲测Android TextView的文字滚动(marquee)效果
- android TextView 垂直自动滚动
- android实现TextView垂直或水平滚动