我正在尝试在RecyclerView中使用多个ViewHolders,以便在运行时交换这些视图.我创建了两个扩展RecyclerView.ViewHolder的类:
MenuItemViewHolder
public class MenuItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView menuItemText;
public ImageView menuItemPhoto;
public RecyclerViewAdapter rva;
public MenuItemViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
rva = caller;
menuItemText = (TextView) itemView.findViewById(R.id.grid_text);
menuItemPhoto = (ImageView) itemView.findViewById(R.id.grid_image);
}
@Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Clicked Position = " + getPosition(), Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
SelectedItemViewHolder
public class SelectedItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView menuItemText;
public ImageView menuItemPhoto;
public RecyclerViewAdapter rva;
public SelectedItemViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
menuItemText = (TextView) …
Run Code Online (Sandbox Code Playgroud) android android-viewholder staggeredgridlayout android-recyclerview recyclerview-layout
我正在使用android中的recyclelerview进行网格布局.网格占据屏幕的一部分并具有阴影.为了获得所需的阴影效果,我使用的是12 dp的高程值.但它似乎不起作用,因为我看不到网格的任何高程(阴影).为什么会这样?recyclerview不支持提升吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/activity_grid_layout"
android:background="@drawable/gradient"
android:layout_height="match_parent"
tools:context="com.mindhive.mindhive.activities.GridActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/grid_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="110dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="80dp"
android:background="@color/transparent"
android:elevation="12dp"
android:scrollIndicators="none"
android:scrollbars="none"
android:padding="0dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/grid_recycler_view"
android:layout_alignStart="@+id/grid_recycler_view"
android:layout_marginBottom="-18dp"
android:layout_marginStart="67dp"
android:src="@drawable/main_filter"
android:elevation="1dp" />
......
Run Code Online (Sandbox Code Playgroud) android recycler-adapter android-recyclerview recyclerview-layout
我有一个我创建的项目列表RecyclerView
.当用户点击其中一个时,我会更改所选项目的背景颜色.问题是,当我滚动浏览我的项目并且它们被回收时,一些项目会获得所选项目的背景颜色(这是错误的).在这里你可以看到我Adapter
的代码:
public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder> {
private static final String SELECTED_COLOR = "#ffedcc";
private List<OrderModel> mOrders;
public OrderAdapter() {
this.mOrders = new ArrayList<>();
}
public void setOrders(List<OrderModel> orders) {
mOrders = orders;
}
public void addOrders(List<OrderModel> orders) {
mOrders.addAll(0, orders);
}
public void addOrder(OrderModel order) {
mOrders.add(0, order);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
// Inflate the custom layout
View contactView = inflater.inflate(R.layout.order_main_item, parent, …
Run Code Online (Sandbox Code Playgroud) 如何recyclerview
在滚动时扩展项目之间的空间,如下所示.我尝试在onBindViewHolder
方法中添加自定义动画,但此解决方案无法正常工作.看起来有些动画添加到RecyclerView.OnScrollListener.onScrolled
方法中.任何的想法?谢谢.
android android-animation android-recyclerview recyclerview-layout
我只是尝试使用glide recyclerview集成并阅读有关它的文档,它说:" RecyclerView集成库使您的应用程序中可以使用RecyclerViewPreloader .RecyclerViewPreloader可以在用户在RecyclerView中滚动的位置之前自动加载图像 ",但是我没有意识到滑翔回收视图集成和滑行之间有什么区别,请说明滑行回收视图集成的进展是什么?我怎么能看出差异?
这是我的代码:
GlideModule.kt
@GlideModule
class GlideModule : AppGlideModule() {
override fun applyOptions(context: Context?, builder: GlideBuilder?) {
val requestOp = RequestOptions.noAnimation()
.priority(Priority.LOW)
builder?.setDefaultRequestOptions(requestOp)
?.setLogLevel(Log.VERBOSE)
super.applyOptions(context, builder)
}
// Disable manifest parsing to avoid adding similar modules twice.
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
MyPreloadModelProvide.kt
class MyPreloadModelProvide(val listUrls: List<String>, val context: Context) : PreloadModelProvider<Any> {
override fun getPreloadItems(position: Int): MutableList<Any> {
val url = listUrls.get(position)
if (TextUtils.isEmpty(url)) {
return Collections.emptyList();
}
return Collections.singletonList(url);
}
override …
Run Code Online (Sandbox Code Playgroud) android kotlin android-recyclerview recyclerview-layout android-glide
我有一个RecyclerView
在我的应用程序一切正常工作我在滚动时最后一项是可见的我在底部添加更多的项目,它工作正常.现在问题是我有一个Handler
每5秒运行一次并检查Web服务是否有任何更新,如果有任何更新我只是将数据加载到它的顶部,RecyclerView
当我还没有滚动时工作正常的RecyclerView
,但是当我滚动在它和Handler
被称为(因为它是每5秒钟之后调用),则在更新RecyclerView
顶部上的应用程序崩溃.
更新顶部的功能:
public void addOnTop(ArrayList<ItemPOJO> topItemList) {
for (int i = topItemList.size() - 1; i >= 0; i--) {
itemList.add(0, topItemList.get(i));
}
notifyItemRangeInserted(0, topItemList.size());
notifyDataSetChanged();
}
Run Code Online (Sandbox Code Playgroud)
这是错误日志:
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{419b8760 position=5 id=-1, oldPos=-1, pLpos:-1 no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4214)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4345)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1364)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1155)
at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1012)
at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1363)
at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2227)
at android.view.View.dispatchTouchEvent(View.java:7190)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2274)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2009)
at …
Run Code Online (Sandbox Code Playgroud) 在执行刷卡刷新视图之前,回收器视图工作正常但不是每当我尝试向下滚动回收器视图时刷卡刷新干扰并阻碍滚动运动.
以下是该问题的屏幕截图:
(注意,当回收器视图向下滚动时,滑动刷新布局会出现)
这是我的布局片段:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/availableTaskRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<RelativeLayout
android:id="@+id/progress_wheel"
android:visibility="gone"
tools:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:background="@color/transparentLoaderBackground">
<com.pnikosis.materialishprogress.ProgressWheel
android:layout_width="50dp"
android:layout_height="50dp"
wheel:matProg_barColor="@color/white"
wheel:matProg_barWidth="1dp"
wheel:matProg_progressIndeterminate="true"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/no_available_tasks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility = "visible"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No tasks currently available. Pull to refresh"
android:layout_centerInParent="true"
android:padding="16dp"
android:gravity="center_horizontal"
android:textSize="18sp"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
下面是我片段的代码:
package com.packrboy.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import …
Run Code Online (Sandbox Code Playgroud) android swiperefreshlayout android-recyclerview recyclerview-layout
我意识到以下是不正确的,但我想你可以把它当作伪代码.我想知道,如何将整个布局"附加"到我的RecyclerView上,这样当我向下滚动布局时,它会随着它滚动出来.目前,RecyclerView上方的TextView固定在屏幕上,而我的RecyclerView中的所有数据都是可滚动的.当用户向下滚动页面时,我希望TextView移出视线.如果您查看Instagram,当您向下滚动页面时,图库顶部的所有用户个人资料信息都会消失.我怎样才能做到这一点?如何以编程方式添加TextView?
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello!" />
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="?android:attr/actionBarSize"
android:padding="@dimen/item_margin"
android:id="@+id/recycler_view"
android:clipToPadding="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello!" />
</android.support.v7.widget.RecyclerView>
Run Code Online (Sandbox Code Playgroud) 我有滚动问题.我的意思是滚动速度很快,但在滚动完成之前看起来像是滞后.在这里我定义__CODE__
:
RecyclerView recyclerView=fragment.getRecyclerView();
LinearLayoutManager layoutManager = new LinearLayoutManager(fragment.getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new DividerItemDecoration(fragment.getActivity(), LinearLayoutManager.VERTICAL));
ArrayList<InstaPostModel> rowListItems=getInstaPostListSample();
InstaPostAdapter rcAdapter = new InstaPostAdapter(rowListItems);
recyclerView.setAdapter(rcAdapter);
Run Code Online (Sandbox Code Playgroud)
这是__CODE__
.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final InstaPostModel p = items.get(position);
context = holder.itemView.getContext();
Glide.with(context).load(R.mipmap.mee_small).into(holder.userPhoto);
Glide.with(context).load(R.drawable.post_image).into(holder.photo_content);
Glide.with(context).load(R.mipmap.love_gray_icon).into(holder.bt_like);
Glide.with(context).load(R.mipmap.comment_icon).into(holder.bt_comment);
Glide.with(context).load(R.mipmap.share_icon).into(holder.bt_share);
holder.userNameTextView.setText(p.getPosterUserName());
holder.postContent.setText(p.getText());
holder.post_date.setReferenceTime(p.getDate().getTime());
}
Run Code Online (Sandbox Code Playgroud)
这是 __CODE__
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/qatar_now_posts_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
tools:context=".uis.fragments.home.QatarNowFragment"
/>
Run Code Online (Sandbox Code Playgroud)
编辑
我有一个底部导航栏__CODE__
,它在滚动时显示.
编辑2
这是显示滞后的视频链接.
编辑3
也许我在测试应用程序时发现了问题.我看到图表和应用程序从Ram内存大约120 MB,但仍然不知道如何解决这个问题.
编辑4
__CODE__
类 …
android smooth-scrolling recycler-adapter android-recyclerview recyclerview-layout