Tag: android recyclerview

NestedScrollView内的Recycler视图使滚动在中间开始

当我在NestedScrollView中添加一个RecyclerView时,我得到了一个奇怪的滚动行为。 会发生什么情况是,只要滚动视图的行数比屏幕上显示的行数多,一旦活动启动,NestedScrollView就会从顶部(图1)开始偏移。 如果滚动视图中的项目很less,以便它们都可以一次显示,则不会发生(图2)。 我正在使用支持库的版本23.2.0。 图1 :错误 – 从顶部偏移开始 图2 :正确 – 回收站视图中的几件物品 我粘贴在我的布局代码下面: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill_vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Title:" style="@style/TextAppearance.AppCompat.Caption"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/bodyPadding" style="@style/TextAppearance.AppCompat.Body1" android:text="Neque porro quisquam est qui dolorem ipsum"/> <TextView android:layout_width="match_parent" […]

如何导入RecyclerView Android L预览

尝试从支持库中使用新的RecyclerView。 我使用SDKpipe理器下载了支持库的20更新。 我已经将jar文件添加到libs文件夹 – 并添加到构buildpath – 使用RecyclerView没有运气。 试图也使用根据Android开发人员的API gradle依赖项 – 不知道这是否是正确的地方看 – 这个页面更关联到AndroidTV: com.android.support:recyclerview-v7:20.0.+ 无法gradle同步项目。 有任何想法吗?

Android RecyclerView:notifyDataSetChanged()IllegalStateException

我试图使用notifyDataSetChanged()来更新recycleview的项目。 这是我在recycleview适配器中的onBindViewHolder()方法。 @Override public void onBindViewHolder(ViewHolder viewHolder, int position) { //checkbox view listener viewHolder.getCheckbox().setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { //update list items notifyDataSetChanged(); } }); } 我想要做的是更新列表项,我检查checkbox后。 我得到一个非法的exception,虽然: "Cannot call this method while RecyclerView is computing a layout or scrolling" java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a […]

RecyclerView中ListView.setEmptyView的等价物

在RecyclerView ,我想设置一个空的视图,当适配器为空时显示。 有没有相当于ListView.setEmptyView() ?

如何添加一个简单的8dp页眉/页脚到Android的RecyclerView?

有没有办法添加一个简单的页眉/页脚到RecyclerView? 在这里你可以看到我有什么。 第一张卡片触摸工具栏 在这里,你可以看到我想要的。 底部和卡之间填充8dp。 我到目前为止尝试的方法: 在我的recyclerview中使用标题视图。 但是我认为这对于每个回收者来说都是非常不够的。 使用8dp的上边距,导致滚动时回收站的顶部/底部出现白条的问题。 在列表项中添加一个填充项,这会在外部和内部卡之间产生不同的边距。 我确信有一个我不知道的简单解决scheme。

RecyclerView GridLayoutManager:如何自动检测跨度计数?

使用新的GridLayoutManager: https : //developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html 它需要一个明确的跨度计数,所以现在的问题变成:你怎么知道每行有多less“跨度”? 毕竟,这是一个网格。 根据测量的宽度,应该有RecyclerView可以容纳的跨度。 使用旧的GridView,你只需设置“columnWidth”属性,它会自动检测有多less列。 这基本上是我会为RecyclerView复制: 在RecyclerView上添加OnLayoutChangeListener 在这个callback中,膨胀单个“网格项”并测量它 spanCount = recyclerViewWidth / singleItemWidth; 这似乎是相当普遍的行为,所以有一个更简单的方法,我没有看到?

尝试在Android 5.0上使用RecyclerView时,应用程序崩溃

我试图搞砸新的RecyclerView,每当我尝试运行它,我的应用程序立即崩溃。 它给我NullPointerException尝试从android.support.v7.widget.RecyclerView访问方法。 我看了其他post,看到大多数人没有compile 'com.android.support:recyclerview-v7:+'但我试过,它根本没有帮助。 真的不知道该怎么做,任何帮助,将不胜感激。 这里的错误日志:(我会张贴图片,但我没有10代表呢) java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.onMeasure(android.support.v7.widget.RecyclerView$Recycler, android.support.v7.widget.RecyclerView$State, int, int)' on a null object reference at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1764) at android.view.View.measure(View.java:17430) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17430) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17430) at […]

Android 5.0 – 添加页眉/页脚到RecyclerView

我花了一些时间试图找出一个方法来添加一个头到一个RecyclerView ,失败。 这是我到目前为止: @Override protected void onCreate(Bundle savedInstanceState) { … layouManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(layouManager); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); headerPlaceHolder = inflater.inflate(R.layout.view_header_holder_medium, null, false); layouManager.addView(headerPlaceHolder, 0); … } LayoutManager似乎是处理RecyclerView项目处置的对象。 由于找不到任何addHeaderView(View view)方法,我决定使用LayoutManager的addView(View view, int position)方法,并在第一个位置添加我的标题视图以像标题一样工作。 Aaand这是更丑陋的地方: java.lang.NullPointerException: Attempt to read from field 'android.support.v7.widget.RecyclerView$ViewHolder android.support.v7.widget.RecyclerView$LayoutParams.mViewHolder' on a null object reference at android.support.v7.widget.RecyclerView.getChildViewHolderInt(RecyclerView.java:2497) at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:4807) at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:4803) […]

ScrollView里面的Recyclerview不能stream畅地滚动

对于我的应用程序,我在ScrollView里面使用了一个RecyclerView , RecyclerView根据它的内容使用这个库 。 滚动正在工作,但是当我滚动RecyclerView时,它不能正常工作。 当我滚动滚动查看本身,它滚动顺利。 我用来定义RecyclerView的代码: LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false); mFriendsListView.setLayoutManager(friendsLayoutManager); mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null)); ScrollView的RecyclerView : <android.support.v7.widget.RecyclerView android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:id="@+id/friendsList" android:layout_width="match_parent" android:layout_height="wrap_content" />

RecyclerView和java.lang.IndexOutOfBoundsException:检测到不一致。 三星设备中的视图持有人适配器positionViewHolder无效

我有一个回收的观点,除三星以外的所有设备完美的作品。 在三星,我明白了 java.lang.IndexOutOfBoundsException:检测到不一致。 无效的视图持有者适配器positionViewHolder 当我回到与从另一个活动的回收者视图的片段。 适配器代码: public class FeedRecyclerAdapter extends RecyclerView.Adapter<FeedRecyclerAdapter.MovieViewHolder> { public static final String getUserPhoto = APIConstants.BASE_URL + APIConstants.PICTURE_PATH_SMALL; Movie[] mMovies = null; Context mContext = null; Activity mActivity = null; LinearLayoutManager mManager = null; private Bus uiBus = null; int mCountOfLikes = 0; //Constructor public FeedRecyclerAdapter(Movie[] movies, Context context, Activity activity, LinearLayoutManager […]