当前位置:首页 » 安卓系统 » android文字滚动

android文字滚动

发布时间: 2023-09-05 08:04:08

① Android中TextView如何实现水平和垂直滚动

殇 殇云的专栏 云的专栏 软件开发锋颤 软件开发 一 一、只想让TextView显示一行,但是文字超过 、只想让TextView显示一行,但是文字超过 在开头显示省略号 android:singleLine="true" android:ellipsize="start" 在结尾显示省略号 android:singleLine="true" android:ellipsize="end" 在中间显示省略号 android:singleLine="true" android:ellipsize="middle" 横向自动滚动(跑马灯效果)段裂 android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" 以上4个效果都要加上�0�2android:singleLine="true",因为TextView默认是会自动换行的 android:marqueeRepeatLimit="marquee_forever"是设置银燃败永远重复,当然你也可以设置具体的数字 android:focusable="true"和android:focusableInTouchMode="true"一定要加上,不然滚动效果出不来在Java代码中加入下面一句话就可以实现垂直滚动

② 安卓开发textview垂直滚动慢

安卓开发textview垂直滚动慢如下,Android TextView可以实现文字平缓垂直自动滚粗银动 ,上面的左右滑动的是AutoHorizontalScrollTextView;下面上下滚动的是AutoVerticalScrollTextView,盯扒上面左右滑动的非常好实凯凳昌现,直接把AutoHorizontalScrollTextView复制到项目中,复制全类名到布局文件中,和系统TextView一样,只需设置文本其他什么都不用设置。

③ android文字横向滚动的自定义view

TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine=”true” 2.设置可滚到,或显示样式
TextView实现文字滚动需要以下几个要点:
1.文字长度长于可显示范围:android:singleLine=”true”
2.设置可滚到,或显示样式:android:ellipsize=”marquee”
3.TextView只有在获取焦点后才会滚动显示隐藏文字,因此需要在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。
自定义一个
AlwaysMarqueeTextView 类
public class AlwaysMarqueeTextView extends TextView { public AlwaysMarqueeTextView(Context context) { super(context); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; }
在布局XML文件中加入这么一个AlwaysMarqueeTextView,这个加入方法也是刚刚学的。
<com.examples.AlwaysMarqueeTextView android:id=“@+id/AMTV1″ android:layout_width=“fill_parent” android:layout_height=“wrap_content” android:lines=“1″ android:focusable=“true” android:focusableInTouchMode=“true” android:scrollHorizontally=“true” android:marqueeRepeatLimit=“marquee_forever” android:ellipsize=“marquee” android:background=“@android:color/transparent” />
ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
focusable属性
自己猜测的,应该是能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点。
组合View的问题:
< LinearLayout xmlns:android =“http://schemas.android.com/apk/res/android” android:orientation =“vertical” android:gravity =“center_vertical” android:background =“@drawable/f_background” android:layout_width =“fill_parent” android:focusable =“true” android:layout_height =“50px” > < TextView android:id =“@+id/info_text” android:focusable =“true” android:layout_width =“fill_parent” android:layout_height =“wrap_content” android:text =“test marquee .. “ android:textColor =“@color/black” android:singleLine =“true” android:ellipsize =“marquee” android:marqueeRepeatLimit =“3″ android:textSize =“18sp” /> < TextView android:id =“@+id/date_text” android:layout_width =“fill_parent” android:layout_height =“wrap_content” android:layout_gravity =“bottom” android:textColor =“@color/gray” android:text =“2010/05/28″ android:textSize =“12sp” /> </ LinearLayout >
上面示例中2个TextView组合为一个View,由于设置了LinearLayout为focusable而TextView就没法取得焦点了,这样 这个TextView的跑马灯效果就显示不出来,就算你也设置TextView的

④ Android Textview怎么实现文字逐个出现并且过长时文本自动向上滚动

把字符串用split拆解成数组,晌派使用定时器往textview追加(append)。向上滚动则可以把textview放在scrollview,在append后面将scrollview滚动陪握到底部宴乱贺

⑤ android studio怎么实现字幕自动滚动

这个Android字幕滚动类的自定义功能比较多,可定义当前滚动到结尾时的停顿时间,单位:毫秒,还可设置当前的滚动速度,值越小,速度越快。

主要实现代码如下:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

package com.tony.autoscroll;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;
/**
* @author Tony
*/
public class AutoScrollView extends ScrollView {
private final Handler handler = new Handler();
private long ration = 50;
private boolean isScrolled = false;
private int currentIndex = 0;
private long period = 1000;
private int currentY = -1;
private double x;
private double y;
private int type = -1;
/**
* @param context
*/
public AutoScrollView(Context context) {
this(context, null);
}
/**
* @param context
* @param attrs
*/
public AutoScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public AutoScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean onTouchEvent(MotionEvent event) {
int Action = event.getAction();
switch (Action) {
case MotionEvent.ACTION_DOWN:
x=event.getX();
y=event.getY();
if (type == 0) {
setScrolled(false);
}
break;
case MotionEvent.ACTION_MOVE:
double moveY = event.getY() - y;
double moveX = event.getX() - x;
Log.d("test", "moveY = " + moveY + " moveX = " + moveX );
if ((moveY>20||moveY<-20) && (moveX < 50 || moveX > -50) && getParent() != null) {
getParent().(true);
}
break;
case MotionEvent.ACTION_UP:
if (type == 0) {
currentIndex = getScrollY();
setScrolled(true);
}
break;
default:
break;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent p_event)
{
Log.d("test", "onInterceptTouchEvent");
return true;
}
/**
* 判断当前是否为滚动状态
* @return the isScrolled
*/
public boolean isScrolled() {
return isScrolled;
}
/**
* 开启或者关闭自动滚动功能
* @param isScrolled
* true为开启,false为关闭
*/
public void setScrolled(boolean isScrolled) {
this.isScrolled = isScrolled;
autoScroll();
}
/**
* 获取当前滚动到结尾时的停顿时间,单位:毫秒
* @return the period
*/
public long getPeriod() {
return period;
}
/**
* 设置当前滚动到结尾时的停顿时间,单位:毫秒
* @param period
*the period to set
*/
public void setPeriod(long period) {
this.period = period;
}
/**
* 获取当前的滚动速度,单位:毫秒,值越小,速度越快。
* @return the speed
*/
public long getSpeed() {
return ration;
}
/**
* 设置当前的滚动速度,单位:毫秒,值越小,速度越快。
* @param speed
*the ration to set
*/
public void setSpeed(long speed) {
this.ration = speed;
}
public void setType(int type){
this.type = type;
}
private void autoScroll() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
boolean flag = isScrolled;
if (flag) {
//Log.d("test", "currentY = " + currentY + " getScrollY() = "+ getScrollY() );
if (currentY == getScrollY()) {
try {
Thread.sleep(period);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex = 0;
scrollTo(0, 0);
handler.postDelayed(this, period);
} else {
currentY = getScrollY();
handler.postDelayed(this, ration);
currentIndex++;
scrollTo(0, currentIndex * 1);
}
} else {
//currentIndex = 0;
//scrollTo(0, 0);
}
}
}, ration);
}
}

⑥ android textview 怎么实现文字滚动

TextView实现文字滚动需要以下几个要点:
1.文字长度长于可显示范围:android:singleLine="true"
2.设置可滚到,或显示样式:android:ellipsize="marquee"
3.TextView只有在获取焦点后才会滚动显示隐藏文字,因此需要在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。focusable属性
能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点

⑦ android 如何让多条数据在一个textview中垂直滚动显示

Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局。只要在layout中简单设置几个属性就可以轻松实现
<TextView
android:id="@+id/tvCWJ"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"<!--垂直滚动条-->
android:singleLine="false"<!--实现多行-->
android:maxLines="15"<!--最多不超过15行-->
android:textColor="#FF0000"
/>
当然我们为了让TextView动起来,还需要用到TextView的setMovementMethod方法设置一个滚动实例,代码如下:
TextViewtvAndroid123=(TextView)findViewById(R.id.tvCWJ);
tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance());//Android开发网提示相关的可以查看SDK中android.text.method分支了解更多

⑧ Android实现横纵滚动标题不动框架

用自定义标题栏。
用自定义标题栏,只要把系统自带的标题栏去掉就行。做法:requestWindowFeature(Window.FEATURE_NO_TITLE),自己再写两个布局块(LinearLayout布局)充当顶部和底部的标题栏即可,中间使用ScrollView即可完成。
如果应用需要添加水平滚动条,则可借助于另一个滚动视图HorizontalScrollView来实现。

⑨ Android中使用SeekBar时如果加滚动文字

用windowmanager实现,拖动的时候,把坐标值传给上面按个小提示框。
上面那个小提示框假设是个button(或者别的view),

windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.width = 50;
params.height = 40;
windowmanager.addView(button);
对seekbar设置setOnTouchListener
捕获MotionEvent.ACTION_DOWN 和MotionEvent.ACTION_MOVE, 获取移动的坐标,传给params

然后调用windowmanager.updateViewLayout(button, params)

热点内容
家用电脑安装服务器内存 发布:2025-02-01 14:38:50 浏览:257
增量调制编译码实验报告 发布:2025-02-01 14:30:30 浏览:787
不良人2无敌伤害脚本 发布:2025-02-01 14:23:04 浏览:398
地图flash源码 发布:2025-02-01 14:13:33 浏览:957
家庭影院配置什么样的音响 发布:2025-02-01 14:04:33 浏览:545
苹果手机存储空间不能用怎么回事 发布:2025-02-01 14:03:04 浏览:259
qq易语言盗号源码 发布:2025-02-01 14:01:25 浏览:812
源神比较好的云服务器 发布:2025-02-01 13:55:27 浏览:208
黑苹果idea编译慢 发布:2025-02-01 13:45:30 浏览:552
c和linux 发布:2025-02-01 13:39:38 浏览:177