如何获得RecycleView的滚动坐标?(How is it possible get scroll coordinates of a RecycleView?)
想要获得
RecycleView
滚动坐标,如下所示:int scrollX = recycleView.getScrollX();
但它始终返回0,即使视图已滚动。 为什么它没有帮助? 如何获得内容的移动距离?
Want to get scroll coordinates of a
RecycleView
like this:int scrollX = recycleView.getScrollX();
But it always returns 0, even though view is already scrolled. Why it does not help? How is it possible get the shifted distance of the content?
原文:https://stackoverflow.com/questions/38981586
最满意答案
您可以简单地测试元组是否为“假”,即为空。 如果是,请返回您的特殊值:
def max_steps(step_records): if not step_records: return None tuplemax = max(step_records, key = lambda x:x[1]) return(tuplemax[1])
但是,不是返回
None
或其他特殊值,而是提出一个特定的异常,让用户确切地知道出了什么问题:def max_steps(step_records): if not step_records: raise ValueError('"step_records" may not be empty') tuplemax = max(step_records, key = lambda x:x[1]) return(tuplemax[1])
You can simply test if the tuple is "falsy" i.e empty. If it is, return your special value:
def max_steps(step_records): if not step_records: return None tuplemax = max(step_records, key = lambda x:x[1]) return(tuplemax[1])
However, rather than returning
None
or some other special value, it would be better to raise a specific exception letting the user know exactly what went wrong:def max_steps(step_records): if not step_records: raise ValueError('"step_records" may not be empty') tuplemax = max(step_records, key = lambda x:x[1]) return(tuplemax[1])
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
只是检查tuple是否为空之后才能使用最后一个元素。 sorted(lst, key=lambda p: bool(p) and p[-1]) 当元组为空时, bool(p) and p[-1]返回False (计算结果为0),否则返回最后一个值。 采用这种方法,如果所有值都是正值,则空元组将排在第一位。 它需要更多的调整才能使它们在泛型中首先或最后出现,仍然可以通过在lambda中返回一个tuple来实现: sorted(lst, key=lambda p: (not bool(p),bool(p) a ...
-
[]可以匹配一个空的元组列表。 但是根据你的类型注释, remaining的不是元组列表,它是一个包含int和int列表的元组。 元组列表将是(int*int) list 。 int * int list被解析为int * (int list) ,而不是(int * int) list 。 如果您修复了类型,您的代码应该可以正常工作。 [] is just fine to match an empty list of tuples. But according to your type annotation ...
-
看起来你想要做的转变是剥离引号字符? 如果是这样,过滤在您的数据上调用show的结果就足够了: > let x = [(1,'a','%',"yes"),(2,'b','[',"no"),(3,'c',']',"ok")] 然后应用过滤器, > putStrLn . filter (`notElem` "'\"") . show $ x [(1,a,%,yes),(2,b,[,no),(3,c,],ok)] 一旦你知道show将数据结构变成一个漂亮的字符串,处理该字符串进行微小的修改就非常容易了。 ...
-
您可以简单地测试元组是否为“假”,即为空。 如果是,请返回您的特殊值: def max_steps(step_records): if not step_records: return None tuplemax = max(step_records, key = lambda x:x[1]) return(tuplemax[1]) 但是,不是返回None或其他特殊值,而是提出一个特定的异常,让用户确切地知道出了什么问题: def max_steps(step_re ...
-
元组列表的所有组合(All combination of a list of tuples)[2022-03-24]
正如其他人建议你应该创建Point类: public partial class Point { public int X { get; set; } public int Y { get; set; } public Point(int x, int y) { this.X = x; this.Y = y; } } 并且,让我们封装用于计算距离和总成本的函数 : public partial class Point { p ... -
我不确定你的比较函数在数学意义上是否是有效的,即传递性的。 给定a, b, c是一个比较函数,说a > b和b > c意味着a > c 。 排序过程依赖于这个属性。 更不用说按照你的规则,对于a = [1, 2]和b = [2, 1]你同时a[1] == b[0]和a[0] == b[1] ,这意味着a比b大和小 。 I'm not sure your comparison function is a valid one in a mathematical sense, i.e. transitive. G ...
-
具有自定义布局的ListFragment:始终显示空消息(ListFragment with custom layout: empty message always displayed)[2023-01-07]
你的布局有点混乱。 new ArrayAdapter(getActivity(), R.layout.headline_list, R.id.my_text, headlines) ArrayAdapter构造函数中的第二个参数是单个行布局的ID,而不是整个Fragment布局。 第三个参数引用行布局中的TextView以显示项目的数据。 您可以提供自己的行布局,也可以使用SDK提供的行布局。 后者的一个例子: new ArrayAdapter (getActivit ... -
我添加了data-err来指示没有结果时显示的span的id。 在init()中添加了跨度还修正了过滤器在没有申请u,n,d,e,f,i('未定义'中的字母)时的错误。 (function(document) { 'use strict'; var LightTableFilter = (function(Arr) { var _input; function _onInputEvent(e) { _i ...