Tag: android recyclerview

RecyclerView中带有折叠工具栏的Android字母快速滚动视图

在我的应用程序中,我有这样的activity_main.xml: <Coordinator Layout> <AppBarLayout> <CollapsingToolbarLayout> <ImageView/> <Toolbar/> </CollapsingToolbarLayout> </AppBarLayout> <RecyclerView/> </Coordinating Layout> Layout.xml —– >>> <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/theme_background" android:id="@+id/drawerlayout" > <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:id="@+id/activity_main_id" tools:context="objectdistance.ajai.ram.sita.gallery.MainActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp" android:fitsSystemWindows="true"> <ImageView android:id="@+id/imagetoolbar" android:layout_width="match_parent" android:layout_height="200dp" […]

RecyclerView在下方滑动查看

我一直在做一些研究,我还没有find一个例子或实现,允许您在滑动时在RecyclerView下面放置一个视图(下图中的示例)。 有没有人有任何例子或如何这将实施而不使用库的想法。 这是我如何实施刷卡解雇。 ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { return super.getSwipeDirs(recyclerView, viewHolder); } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { if (viewHolder instanceof ViewDividers) { Log.e("DIRECTION", direction + ""); } […]

RecyclerView在NestedScrollView中使用时不会回收视图

我在NestedScrollView内使用RecyclerView 。 另外我设置setNestedScrollingEnabled为false为recyclerview 支持较低的API ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); 现在! 当用户滚动视图的每件事情似乎没关系,但! recyclerview中的视图不会被回收! 堆大小迅速增长! 更新 :RecyclerView布局pipe理器是StaggeredLayoutManager fragment_profile.xml : <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" > </android.support.design.widget.AppBarLayout> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/profileSwipeRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" > <!– RecyclerView and NestedScrollView –> <include layout="@layout/fragment_profile_details" /> </android.support.v4.widget.SwipeRefreshLayout> </android.support.design.widget.CoordinatorLayout> fragment_profile_details.xml : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rootLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" […]

如何更新/刷新RecyclerView中的特定项目

我正在尝试刷新RecyclerView特定项目。 故事:每当用户点击项目,它显示AlertDialog 。 用户可以通过点击确定button来input一些文字。 我想在这个项目中显示这个文本,并显示不可见的ImageView – 在XML和适配器ViewHolder – 我在AlertDialog Positive Button中使用这个函数来更新这个项目: private void updateListItem(int position) { View view = layoutManager.findViewByPosition(position); ImageView medicineSelected = (ImageView) view.findViewById(R.id.medicine_selected); medicineSelected.setVisibility(View.VISIBLE); TextView orderQuantity = (TextView) view.findViewById(R.id.order_quantity); orderQuantity.setVisibility(View.VISIBLE); orderQuantity.setText(quantity + " packet added!"); medicinesArrayAdapter.notifyItemChanged(position); } 但是这段代码不仅改变了传递位置处的itemView,还改变了其他一些itemView(s)! 点击它应该如何正确更改特定的itemView?

在Android中使用notifyItemRemoved或notifyDataSetChanged与RecyclerView

我正在创build一个使用RecyclerView显示的卡片列表,其中每张卡片都有一个button来从列表中删除该卡片。 当我使用notifyItemRemoved()删除RecyclerView中的卡时,它删除项目和animation罚款,但列表中的数据不正确更新。 如果不是这样,我切换到notifyDataSetChanged()然后列表中的项目被删除并正确更新,但然后卡不animation。 有没有人有使用notifyItemRemoved()的经验,知道为什么它的行为不同于notifyDataSetChanged? 以下是我正在使用的一些代码: private List<DetectedIssue> issues = new ArrayList<DetectedIssue>(); @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { // – get element from your dataset at this position // – replace the contents of the view with that element if(position >0){ RiskViewHolder riskHolder = (RiskViewHolder)holder; final int index = position – 1; final DetectedIssue […]

在RecyclerView上删除项目时没有animation

我第一次使用RecyclerView 。 一切都工作正常,除了没有项目删除animation,即使在项目添加animation工作得很好。 我没有设置任何自定义项目animation师,但根据文档 : RecyclerView默认启用添加和删除项目的animation。 所以去除animation应该工作。 我想有删除的默认animation,但不能得到这个工作。 这是我如何设置RecyclerView: private void setupRecyclerView() { mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); View emptyView = mRootView.findViewById(R.id.empty_view); mAdapter = new RoutineAdapter(getActivity(), mRoutineItems, emptyView); mRecyclerView.setAdapter(mAdapter); } 这是我的适配器: private class RoutineAdapter extends RecyclerView.Adapter<RoutineAdapter.ViewHolder> { private final Context mContext; private List<RoutineItem> mData; private View mEmptyView; public RoutineAdapter(Context context, List<RoutineItem> data, View emptyView) […]

Android:如何获得RecyclerView的当前X偏移量?

我正在使用一个Scrollview查看一个无限的“时间select器旋转木马”,并发现,这不是最好的办法( 最后一个问题 ) 现在,我find了Recycler View,但是我无法获得recyclerView的X方向上的当前滚动偏移量 ? (假设每个项目的宽度是100px,第二个项目只能看到50%,所以scroll-offset是150px) 所有项目都有相同的宽度,但是在最后一个项目之后的第一个项目之前有一些差距 recyclerView.getScrollX()返回0 (文档说:初始滚动值) LayoutManager有findFirstVisibleItemPosition ,但是我不能用这个来计算X偏移量 UPDATE 我只是find了一种方法来跟踪X位置,同时使用onScrolledcallback来更新值,但我更喜欢获取实际值而不是始终跟踪它! private int overallXScroll = 0; //… mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); overallXScroll = overallXScroll + dx; Log.i("check","overallXScroll->" + overallXScroll); } });

如何突出显示Recycler View的选定项目?

从内部存储器加载的图像中有一个Recycler View。 我想单击时突出显示所选项目。 我尝试了很多东西,但没有成功。 其实我需要的是,当我点击Recycler View中的任何项目,项目必须在我的ArrayList中,它也应该突出显示,当我点击或说取消select它必须再次成为正常。 这是我的代码: public class Images extends Fragment { private List<ImageHolder> imageList; Cursor imageCursor; RecyclerView recyclerView; MyImageAdapter adapter; ActionButton clickButton; List<String> listofImages; List<Integer> pos; int columnIndex; StringBuilder stringBuilder; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootlayout = inflater.inflate(R.layout.image, container, false); listofImages=new ArrayList<String>(); pos=new ArrayList<Integer>(); stringBuilder=new StringBuilder(); ContentResolver […]

RecyclerView水平滚动中心

我试图在这里使用RecyclerView制作一个类似于旋转木马的视图,我希望项目在滚动时捕捉屏幕中间,一次一个项目。 我试过使用recyclerView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING); 但视图仍然顺利滚动,我也尝试使用滚动监听器实现我自己的逻辑,如下所示: recyclerView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); Log.v("Offset ", recyclerView.getWidth() + ""); if (newState == 0) { try { recyclerView.smoothScrollToPosition(layoutManager.findLastVisibleItemPosition()); recyclerView.scrollBy(20,0); if (layoutManager.findLastVisibleItemPosition() >= recyclerView.getAdapter().getItemCount() – 1) { Beam refresh = new Beam(); refresh.execute(createUrl()); } } catch (Exception e) { e.printStackTrace(); } } 从右向左滑动现在可以正常工作,但是相反,我在这里错过了什么?

如何把RecyclerView里面的NestedScrollView?

创buildNestedScrollView ,只要那些实现了NestedScrollingChild和NestedScrollingParent ,就可以将滚动视图放在另一个滚动视图中。 (这不是糟糕的devise模式“Ian Lake(来自Google)实际上build议在这里添加一个RecyclerView在一个nestedscrollview中:plus.google.com/u/0/+AndroidDevelopers/posts/9kZ3SsXdT2T”) 我想把RecyclerView放在NestedScrollView中 ,幸运的是RecyclerView实现了NestedScrollingChild,所以你可以把它放在NestedScrollView中 。 public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild 我读过这些post: 如何在NestedScrollView中使用RecyclerView? NestedScrollView,RecyclerView(水平),在CoordinatorLayout内 但是大多数投票解决scheme的问题是,它调用RecyclerView所有项目,例如,如果它是一个无尽的RecyclerView,并且当用户到达列表的末尾,您想要发出networking请求,那么RecyclerView调用该解决scheme服务器反复,因为它会自动到达RecyclerView的最后一个项目。 无论如何,如何设置参数,所以我可以把RecyclerView里面的NestedScrollView (实际上我想把一个像framelayout或relativelayout作为一个nestedscrollview单一的childe,然后我想把recyclerview里面framelayout或relativelayout) 当我把RecyclerView放在NestedScrollView里面的时候什么也没有显示。 为了创build示例项目,您可以使用cheesesquare并将CheeseDetailActivity更改为具有RecyclerView。 虽然BNK的答案不正确,但BNK已经尝试了很多。 所以我给他赏金。 仍然在寻找好的解决scheme….