目前我正在使用以下代码来检查是否应启用SwipeRefreshLayout.
private void laySwipeToggle() {
if (mRecyclerView.getChildCount() == 0 || mRecyclerView.getChildAt(0).getTop() == 0) {
mLaySwipe.setEnabled(true);
} else {
mLaySwipe.setEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
但这是问题所在.当它滚动到另一个项目的视图时,边界mRecyclerView.getChildAt(0).getTop()也会返回0.

有什么像RecyclerView.isScrolledToBottom()或RecyclerView.isScrolledToTop()?
编辑:(mRecyclerView.getChildAt(0).getTop() == 0 && linearLayoutManager.findFirstVisibleItemPosition() == 0)有点做RecyclerView.isScrolledToTop(),但是怎么样RecyclerView.isScrolledToBottom()?
更新:我认为它工作正常.但经过一些测试仍然存在麻烦*嗅*
然后我做了一个更简单的版本,看看究竟发生了什么,并且我知道应该已经分离的刷新片段仍然留在那里.或者确切地说,旧片段的视图留在那里,在较新的片段之上.由于RecyclerView的原始应用程序的背景不透明,所以我之前说过.
更新结束
我有这样的MainActivity布局:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. --> …Run Code Online (Sandbox Code Playgroud) android android-fragments swiperefreshlayout android-recyclerview
我有一个用例,我需要RecyclerView从适配器内部引用父,特别是在onBindViewHolder方法内.到目前为止,我正在做的是将它分配给onCreateViewHolder传递viewGroup parentarg 的方法中的私有类成员,如下所示:
private ViewGroup mParent;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// inflater logic.
mParent = parent;
}
Run Code Online (Sandbox Code Playgroud)
并引用父RecyclerView在onBindViewHolder这样的:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// binder logic.
((RecyclerView)mParent).blahBlahBlah();
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?也许RecyclerView.Adapter有一种我可能错过的方式?
我试图在增加最后一个元件行下面的间距RecyclerView有GridLayoutManager.ItemDecoration为了这个目的,我使用自定义底部填充,当它的最后一个元素如下:
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
private int space;
private int bottomSpace = 0;
public SpaceItemDecoration(int space, int bottomSpace) {
this.space = space;
this.bottomSpace = bottomSpace;
}
public SpaceItemDecoration(int space) {
this.space = space;
this.bottomSpace = 0;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
int childCount = parent.getChildCount();
final int itemPosition = parent.getChildAdapterPosition(view);
final int itemCount = state.getItemCount();
outRect.left = space;
outRect.right = space;
outRect.bottom = space; …Run Code Online (Sandbox Code Playgroud) 在ListView上,您可以使用快速滚动条,允许您拖动滚动条以轻松滚动到您希望的任何位置(使用fastScrollEnabled属性)
与" SectionIndexer "类和可选的一些属性一起,您可以在使用此滚动条时显示一个很好的弹出窗口(此处链接).
联系人应用程序上会显示这样的内容,以便您可以轻松滚动到特定字母.
RecyclerView似乎没有任何这些.甚至不是快速滚动.
如何为RecyclerView添加快速滚动功能?
android scrollbar fastscroll sectionindexer android-recyclerview
Android支持库22.1昨天发布.v4支持库和v7中添加了许多新功能,其中android.support.v7.util.SortedList<T>引起了我的注意.
据说,SortedList是一种新的数据结构,可以使用RecyclerView.Adapter,维护项目添加/删除/移动/更改的动画RecyclerView.这听起来像一个List<T>在ListView,但似乎更先进,更强大.
那么,SortedList<T>和之间有什么区别List<T>?我怎么能有效地使用它?如果是这样的话,执行SortedList<T>结束的List<T>是什么?有人可以发一些样品吗?
任何提示或代码将不胜感激.提前致谢.
我基于创建列表和卡片指南创建了RecyclerView示例.我的适配器只有一个模式实现来扩展布局.
问题是滚动性能差.这在RecycleView中只有8个项目.
在一些测试中我验证了在Android L中没有出现这个问题.但在KitKat版本中,性能的下降是显而易见的.
java performance android recycler-adapter android-recyclerview
我很想为我的开源库启用触摸反馈.
我创造了一个RecyclerView和一个CardView.该CardView包含不同的区域不同的onClick动作.现在,如果用户点击卡中的任何位置,我很乐意触发Ripple效果,但我无法实现此行为.
这是我的listitem,您也可以在GitHub上找到它:https://github.com/mikepenz/AboutLibraries/blob/master/library/src/main/res/layout/listitem_opensource.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/button_rect_normal"/>
<LinearLayout
android:padding="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/libraryName"
android:textColor="@color/title_openSource"
android:textSize="@dimen/textSizeLarge_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/libraryCreator"
android:textColor="@color/text_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="right"
android:maxLines="2"
android:textSize="@dimen/textSizeSmall_openSource"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<TextView
android:id="@+id/libraryDescription"
android:textSize="@dimen/textSizeSmall_openSource"
android:textStyle="normal"
android:textColor="@color/text_openSource"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="20">
</TextView>
<View
android:id="@+id/libraryBottomDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<LinearLayout
android:id="@+id/libraryBottomContainer"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingRight="8dp" …Run Code Online (Sandbox Code Playgroud) android touch-feedback android-cardview rippledrawable android-recyclerview
我在recyclerview中有一个开关,在从DB检索数据后,数据显示在recyclerview中.打开recyclerview时,我读DB,如果DB中的字段是"Y",我启用开关,否则我禁用开关.现在问题是它还调用了onCheckedchanged侦听器,我希望只有当用户手动设置开关时才调用onCheckedChanged.
在打开时,执行下面的recyclerview:
holder.enabledisable.setChecked(messengerRecord.get_is_valid().equalsIgnoreCase("Y"));
Run Code Online (Sandbox Code Playgroud)
ViewHolder类:
public class viewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener{
public SwitchCompat enabledisable;
public viewHolder(View v) {
enabledisable = (SwitchCompat) v.findViewById(R.id.enabledisable);
enabledisable.setOnCheckedChangeListener(this);
...................................
...................................
Run Code Online (Sandbox Code Playgroud)
刚刚打开recyclerView时调用的OncheckedChanged方法:
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.v("ranjith","called oncheckedchanged");
MessengerRecord rec;
rec = dbHelper.getRecord(descview.getText().toString());
switch (buttonView.getId()) {
case R.id.enabledisable:
if (isChecked) {
rec.set_is_valid("Y");
dbHelper.updateRecord(rec);
}
}
Run Code Online (Sandbox Code Playgroud)
在布局文件中:
<android.support.v7.widget.SwitchCompat
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:id="@+id/enabledisable"
android:layout_alignRight="@+id/textview_to"
android:layout_alignEnd="@+id/textview_to"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
Run Code Online (Sandbox Code Playgroud) android oncheckedchanged android-switch switchcompat android-recyclerview