我正在开发一个看起来像这样的应用程序:

RecyclerView使用自定义LayoutManager,其自定义实现为"scrollVerticallyBy"
首先.recyclerview滚动黄油平滑并且以低于所需的16毫秒的方式呈现.我想我可以在Nexus 5上大约5毫秒.
但是,我还希望能够滚动RecyclerView触摸它上方的View(它是RelativeLayout).
这是问题所在:
1)如果我只是转发onTouchEvents,滚动是黄油平滑的.但是,只有在手指触摸屏幕时,才会调用RecyclerView.fling(...)并且只能滚动.没有投掷感觉非常尴尬.
@Override
public boolean onTouchEvent(MotionEvent event) {
return mRecyclerView.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
2)如果我在RecyclerView中覆盖.fling(...),我可以使用Scroller进行"投掷"工作.这有效,但确实会导致一些奇怪的大滞后.
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mScroller.computeScrollOffset()) {
Log.d("RecyclerView", "(ondraw) Y: " + mScroller.getCurrY());
scrollBy(0, mScroller.getCurrY()- mLastY);
mLastY = mScroller.getCurrY();
postInvalidateDelayed(16); // 60 Hz
}
}
@Override
public boolean fling(int velocityX, int velocityY) {
mLastY = 0;
mScroller.fling(0, 0, velocityX, velocityY, 0, 0, -10000 ,10000);
return true;
}
Run Code Online (Sandbox Code Playgroud)
我不确定这样做的正确方法是什么.我觉得如果我没有覆盖.fling()并强制我的应用程序通过使用Scroller重复调用scrollBy()滚动工作方式不同.
我怀疑这可能与"startSmoothScroll"和"smoothScrollToPosition"有关,我还没有覆盖.老实说,我不知道smoothscrolling是什么,但这听起来与这个问题有关:)
android scroll smooth-scrolling android-layout android-recyclerview
我在一段时间内拍摄了一系列大致相同的图像.但是,图像中的对象会随着时间的推移而漂移,我想纠正这个问题.这样做有什么好处?
[编辑]好的,我可能要解释为什么我会这样做.我拍摄了一系列不同X射线能量的物体X射线图像.我现在想要比较对象是各种能量,但由于它漂移我必须首先纠正漂移.该对象没有锐利边缘或任何其他易于用于对齐的东西.因此,我正在寻找一种更通用的方法
我和Rails和mongodb有一个小问题.我有一个小应用程序,在开发模式下工作得很好.它也可以在生产模式下工作,但是当我进入rails控制台时,我看不到任何内容.
user-001@marcus:/var/www/webapp% rails c RAILS_ENV="production"
You did not specify how you would like Rails to report deprecation notices for your RAILS_ENV=production environment, please set config.active_support.deprecation to :log, :notify or :stderr at config/environments/RAILS_ENV=production.rb
Loading RAILS_ENV=production environment (Rails 3.2.1)
1.9.3p0 :001 > User.all
=> []
Run Code Online (Sandbox Code Playgroud)
我的config/initialize/mongo.rb看起来像这样
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "webapp-#{Rails.env}"
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect if forked
end
end
Run Code Online (Sandbox Code Playgroud)
但它看起来也是空的
$ mongo localhost:27017/mail1up-production
MongoDB shell version: 1.8.2
Fri Feb 17 18:26:00 *** warning: spider monkey build without utf8 …Run Code Online (Sandbox Code Playgroud) 我在公共视图中有一个带有以下(测试)代码的适配器getView(int position,View convertView,ViewGroup parent):
Cursor itemCursor = (Cursor) getItem(position);
Cursor itemCursor2 = (Cursor) getItem(position+1);
String itemTitle = itemCursor.getString(itemCursor
.getColumnIndex(ItemColumns.TITLE));
String itemTitle2 = itemCursor2.getString(itemCursor2
.getColumnIndex(ItemColumns.TITLE));
Run Code Online (Sandbox Code Playgroud)
我重写"DragSortCursorAdapter",因此重写getItem()看起来像这样:
@Override
public Object getItem(int position) {
int item = mListMapping.get(position, position);
return super.getItem(item);
//return super.getItem(position);
}
Run Code Online (Sandbox Code Playgroud)
从这里调用的getItem是"android.support.v4.widget.CursorAdapter.getItem"的常规实现
问题是itemCursor和itemCursor2始终是同一个对象.使用相同的对象ID和所有内容 - 我不知道这是如何可能的,因为使用不同的参数调用getItem,并且输出到屏幕的列表仅显示不同的值.
换句话说,当我的适配器迭代列表时,它似乎这样做:
第一个清单项目:
Cursor itemCursor = (Cursor) getItem(0);
Cursor itemCursor2 = (Cursor) getItem(0+1);
Run Code Online (Sandbox Code Playgroud)
itemCursor和itemCursor2都是413d4800
第二个清单项目:
Cursor itemCursor = (Cursor) getItem(1);
Cursor itemCursor2 = (Cursor) getItem(1+1);
Run Code Online (Sandbox Code Playgroud)
itemCursor和itemCursor2现在都是4155aef8
至少不应该从第一次迭代中的itemCursor2和第二次迭代中的itemCursor2相同吗?
无论如何 - 有人可以帮我解决这里发生的事情吗?他们都有类型"android.content.ContentResolver$CursorWrapperInner@4155aef8",可能相关或不相关 - 我不确定. …
我正在尝试将一些旧的C代码重写为Rust - 我是新手.我遇到的一个反复出现的问题是C代码有很多这样的循环:
for (i = startIndex; i < asize; i++)
{
if (firstEdge < 0 && condLeft(i))
{
firstEdge = i;
}
RightIndex = asize-1-i;
if (firstEdgeRight < 0 && condRight(RightIndex))
{
firstEdgeRight = RightIndex;
}
// Found both edges
if (firstEdge >= 0 && firstEdgeRight >= 0) {
break;
}
}
Run Code Online (Sandbox Code Playgroud)
你会如何以高效的方式将其转化为Rust?我的问题是,虽然我可能得到我想要的功能,但我不确定如何获得(大致)相同的速度.
这部分代码是我们代码中的主要瓶颈(至少这部分代码),并且在翻译时它希望保留以下属性.
asize它可能非常大.firstEdge并firstEdgeRight在同一时间大致找到.因此,只有一个循环而不是两个循环是一件好事 - 为了避免再次从头开始搜索(即使我认为这个解决方案会杀死预取器(但我不确定,也许旧机器运行代码)甚至没有预取器)).虽然性能很重要,但可读性当然更为重要:)
编辑好的,这是我可能实现的Rust(cond_right()并且cond_left()被遗漏了).我想到的是:
first_edge和first_edge_right变异吗?它们在我的实现中,但我感觉不对,因为它们只被分配一次.let mut …Run Code Online (Sandbox Code Playgroud)