- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经实现了 Android Note Pad 示例代码中的编辑器代码。现在我想添加垂直滚动文本行的功能。我想要完成的一个例子是在 Andorid 中快速滚动选项行
我在 Google 上搜索了 scroller 和 fling 的例子,但我找不到任何适合我需要的东西。我还没有发现任何与我正在尝试做的事情相差甚远的事情。
最佳答案
我已经通过鲜血、汗水和泪水找到了我的问题的答案。我会把它贴在这里,希望它能帮助别人。以下方法位于 Android Note Pad 示例代码中的 LinedEditText 类中。
============================
public void InitScroller(Context context) {
mScroller = new Scroller(context); // Get a scroller object
mScrollY = 0 ; // Set beginning of program as top of screen.
mMinScroll = getLineHeight ()/2; // Set minimum scroll distance
mFlingV = 750; // Minimum fling velocity
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
if (mVelocityTracker == null) { // If we do not have velocity tracker
mVelocityTracker = VelocityTracker.obtain(); // then get one
}
mVelocityTracker.addMovement(event); // add this movement to it
final int action = event.getAction(); // Get action type
final float y = event.getY(); // Get the displacement for the action
switch (action) {
case MotionEvent.ACTION_DOWN: // User has touched screen
if (!mScroller.isFinished()) { // If scrolling, then stop now
mScroller.abortAnimation();
}
mLastMotionY = y; // Save start (or end) of motion
mScrollY = this.getScrollY(); // Save where we ended up
mText.setCursorVisible (true);
didMove = false;
break;
case MotionEvent.ACTION_MOVE: // The user finger is on the move
didMove = true;
final int deltaY = (int) (mLastMotionY - y); // Calculate distance moved since last report
mLastMotionY = y; // Save the start of this motion
if (deltaY < 0) { // If user is moving finger up screen
if (mScrollY > 0) { // and we are not at top of text
int m = mScrollY - mMinScroll; // Do not go beyond top of text
if (m < 0){
m = mScrollY;
}else m = mMinScroll;
scrollBy(0, -m); // Scroll the text up
}
} else
if (deltaY > 0) { // The user finger is moving up
int max = getLineCount() * getLineHeight () - sHeight; // Set max up value
if (mScrollY < max-mMinScroll){
scrollBy(0, mMinScroll); // Scroll up
}
}
postInvalidate();
break;
case MotionEvent.ACTION_UP: // User finger lifted up
final VelocityTracker velocityTracker = mVelocityTracker; // Find out how fast the finger was moving
velocityTracker.computeCurrentVelocity(mFlingV);
int velocityY = (int) velocityTracker.getYVelocity();
if (Math.abs(velocityY) > mFlingV){ // if the velocity exceeds threshold
int maxY = getLineCount() * getLineHeight () - sHeight; // calculate maximum Y movement
mScroller.fling(0, mScrollY, 0, -velocityY, 0, 0, 0, maxY); // Do the filng
}else{
if (mVelocityTracker != null) { // If the velocity less than threshold
mVelocityTracker.recycle(); // recycle the tracker
mVelocityTracker = null;
}
}
break;
}
mScrollY = this.getScrollY(); // Save where we ended up
return true ; // Tell caller we handled the move event
}
public void computeScroll() { // Called while flinging to execute a fling step
if (mScroller.computeScrollOffset()) {
mScrollY = mScroller.getCurrY(); // Get where we should scroll to
scrollTo(0, mScrollY); // and do it
postInvalidate(); // the redraw the sreem
}
}
关于android - Android中文本行的垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6422697/
我在服务器上创建了一个 JSONP 函数并像这样返回一个 UTF-8 编码的 json 对象 applyLocalization({"Name":"%E5%90%8D%E5%89%8D","Age":
我正在开发一个应用程序,在该应用程序中我从API获取数据,并且正在获取这样的汉字 “u9c9cu82b1u548cu7231” 鲜花和爱 如何转换? 最佳答案 您的字符串采用转义的unicode格式。
好吧,我已经有了这个正则表达式,用于我网站上允许的名称。但是,我还希望添加名称可能使用的其他字母。有人有好的 regex 或知道如何使它更完整吗?我已经搜索了一段时间,但找不到适合我需要的内容。 这是
好吧,我已经有了这个正则表达式,用于我网站上允许的名称。但是,我还希望添加名称可能使用的其他字母。有人有好的 regex 或知道如何使它更完整吗?我已经搜索了一段时间,但找不到适合我需要的内容。 这是
本文实例讲述了Yii框架多语言站点配置方法。分享给大家供大家参考,具体如下: 这里假设我们要建立 中文/英文 切换的站点 1. 设置全局默认的语言 文件添加代码:protected/confi
我想知道如何设置编码参数,以便当我下载文本时,它“看起来”与我在网络浏览器中的页面源代码中看到的一样,例如: readLines("http://www.baidu.com/s?wd=r+projec
我计划开发一个 web 应用程序,它将使用一种新颖的方式来帮助人们学习汉字并记住它们的含义。 由于我不想/不能花费数年时间手动翻译所有中文字符,我想知道是否有(最好是开源的)数据库(任何形式)提供此功
我知道我的问题已经在这里有了解决方案。但我只想具体说明我的情况。我有一个 json 对象,其中包含非英语字符。 例如。 {“my_chinise_name”:“吉米”}。 该对象将通过 javascr
我有一个设置,其中邮件服务器(postfix)收到的电子邮件被处理,生成的电子邮件的正文(html或纯文本)和附件被解析为单独的文件并保存,为此我使用javax mail api。 当电子邮件正文为中
我的 settings.py 看起来像这样: LANGUAGES = ( ('en', _('English')), ('fr', _('French')), #Simplif
在我的图表中,x轴需要显示中文,y轴需要显示英文,但x轴显示困惑的代码。有人可以帮助我吗? self.chart.createDefaultAxes() axis_x, axis_y = self.c
使用Python3和BeautifulSoup v4 url='http://www.eurobasket2015.org/en/compID_qMRZdYCZI6EoANOrUf9le2.seaso
我的开发应用程序名称为中文。今天我从 CoreData 收到错误: CoreData: warning: Unable to load class named '゚ᆪンレ.' for enti
我正在用 java 编写一个 rss feed 解析器,在解析包含阿拉伯文/中文/日文字符的 feed 时遇到了问题。 Example feed 当我打印它们时,我只是得到一组问号“?????? ??
在我的一个Python程序(python 2.7)中,我需要处理一些汉字: 我有一个文件A.txt,它有两列:“name”和“score”,“name”列可以取一些中文字符串,score是一个1 到
我正在学习使用 eclipse 和 ADT 插件在 Android 上开发应用。 根据android SDK 文档中的这篇文章http://androidappdocs.appspot.com/res
我有这样的中文文字:“回家” - 好像是英文的“house”。 我去 google.com,在搜索中输入“回家”并得到这样的 url: http://www.google.ru/... q=%E5%9
我正在为我的应用程序添加中文支持。 我有这条线可以对英语和其他语言进行排序 NSSortDescriptor *sortByItem = [NSSortDescriptor sortDesc
我读日语,想尝试处理一些日语文本。我使用 Python 3 尝试了这个: for i in range(1,65535): print(chr(i), end='') 然后 Python 给了
我想将文本框值翻译成特定语言,如西类牙语、中文、德语等,它们都在下面的下拉列表中,我想在标签中显示文本框翻译值,但不在标签中显示翻译值。 English J
我是一名优秀的程序员,十分优秀!