當前位置:首頁 » 安卓系統 » 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 15:30:23 瀏覽:354
javac工資 發布:2025-02-01 15:24:28 瀏覽:22
如何刪除伺服器登錄賬號 發布:2025-02-01 15:21:05 瀏覽:498
瑞薩編程器 發布:2025-02-01 15:19:18 瀏覽:85
上海ntp伺服器搭建 發布:2025-02-01 15:03:38 瀏覽:991
c游戲編程基礎 發布:2025-02-01 15:00:17 瀏覽:993
routejs怎麼動態配置 發布:2025-02-01 14:59:07 瀏覽:502
家用電腦安裝伺服器內存 發布:2025-02-01 14:38:50 瀏覽:257
增量調制編解碼實驗報告 發布:2025-02-01 14:30:30 瀏覽:787
不良人2無敵傷害腳本 發布:2025-02-01 14:23:04 瀏覽:398