我实现了一个ReceylerView,我无法弄清楚如何获得触摸反馈(来自它的涟漪效应).
这是我为onClickListener所做的:
holder.itemView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//start Intent
}
});
Run Code Online (Sandbox Code Playgroud)
我将可点击和可聚焦添加到我的XML中.这是回收者视图膨胀的内容:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:padding="4dp" >
Run Code Online (Sandbox Code Playgroud) java android android-listview recycler-adapter android-recyclerview
我有一个RecyclerView,它在每个特定时期添加项目.添加对象时,如果列表项超过(假设)500,则将删除第一个项目并添加新项目.
如果RecyclerView不能再向下滚动,!recyclerView.canScrollVertically(1);那么在添加新项目后,RecyclerView将smoothScroolToPosition()到达最后一个位置.
问题出在哪儿? 好吧,如果ReyclerView在移除旧物品时位于中间(不是底部,而不是顶部),它会突然跳起一些位置.我希望RecyclerView不会跳转位置并保持在顶部移除物品时的位置
我尝试过layoutManager.setStackFromEnd(true);但没有运气
有什么建议?
一些代码(不相关的代码被删除).当RecyclerView从中间显示列表项并按VOLUME_UP时,我的问题可以重现:
public class ActivityMain extends ActionBarActivity {
public static final int MAX_LOG_ITEMS = 500;
private RecyclerView mRecyclerView;
private AdapterLog mRecyclerAdapter;
private boolean mAutoScroll = true;
private DataReceiver mDataReceiver;
private Handler mLogHandler = new Handler() {
@Override public void handleMessage(Message msg) {
switch (msg.what){
case DataReceiver.CAT_LOGS:
List<Log> catLogs = (List<Log>) msg.obj;
updateLogs(catLogs);
break;
case DataReceiver .CLEAR_LOGS:
if (mRecyclerAdapter.getItemCount() > MAX_LOG_ITEMS)
mRecyclerAdapter.removeFirstItems(mRecyclerAdapter.getItemCount() - MAX_LOG_ITEMS);
break;
case Logcat.REMOVE_LOGS:
mRecyclerAdapter.clear();
}
} …Run Code Online (Sandbox Code Playgroud) 我有RecyclerView,它可以根据需要显示图像
RecyclerView detailsRecycleImage = (RecyclerView) view.findViewById(R.id.detailsRcycleImage);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(
getActivity().getApplicationContext(),
LinearLayoutManager.HORIZONTAL,
false
);
detailsRecycleImage.setLayoutManager(mLayoutManager);
ImagesAdapter imgAdapter = new
ImagesAdapter(getActivity(),contactsData.getContactImages());
detailsRecycleImage.setAdapter(imgAdapter);
Run Code Online (Sandbox Code Playgroud)
我的适配器代码是
public class ImagesAdapter extends RecyclerView.Adapter<ImagesAdapter.MyViewHolder>{
private Context cnt;
public ArrayList<String> imgsUrls;
public ImagesAdapter(Context cnt, ArrayList<String> imgsUrls) {
this.cnt=cnt;
this.imgsUrls=imgsUrls;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_img,parent,false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
String singleImg = imgsUrls.get(position);
Picasso.with(cnt).load(singleImg).into(holder.img);
}
@Override
public int getItemCount() {
return …Run Code Online (Sandbox Code Playgroud) 我在片段中有一个回收者视图,基本上我试图在回收者视图中加载歌曲列表.每行回收者视图包含一个imageview(用于专辑封面)和textview(用于歌曲名称).我遇到麻烦,当数据集的大小很大时,即当歌曲太多时,回收者视图滞后,应用程序最终给出ANR.我正在使用Glide在每行的imageview中加载专辑艺术.谷歌音乐播放器如何能够显示如此大量的歌曲而没有任何延迟?
编辑: 这是我的SongsFragment
public class SongsFragment extends Fragment {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
ProgressBar progressBar; // progress bar to show after every 30 items
NestedScrollView nestedScrollView; //for smooth scrolling of recyclerview as well as to detect the end of recyclerview
RecyclerView recyclerView;
ArrayList<Song> songMainList = new ArrayList<>(); //partial list in which items are added
ArrayList<Song> songAllList = new ArrayList<>(); //Complete List of songs
SongAdapter songsAdapter;
private LinearLayoutManager layoutManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, …Run Code Online (Sandbox Code Playgroud) android mediastore recycler-adapter android-recyclerview android-glide
public void onBindViewHolder(VH holder, int position, List<Object> payloads) {
onBindViewHolder(holder, position);
}
Run Code Online (Sandbox Code Playgroud)
我知道当我们想更新RecyclerView项目中的某些视图而不是全部时,我可以使用
public final void notifyItemChanged(int position, Object payload) {
mObservable.notifyItemRangeChanged(position, 1, payload);
}
Run Code Online (Sandbox Code Playgroud)
如该代码所示,param是一个对象,但是为什么在Adapter中将其更改为list,而我必须使用它list.get(0)来找到我的有效载荷?
谢谢
我正在研究类似于'谷歌收件箱'的东西,这需要我在recyclerView中有多个webview,我可以通过点击标题来扩展和折叠内容,这将添加/删除标题下的webview.
到目前为止,这是该项目的要点
Fragment
-> RecyclerView (match_parent on height and width)
-> Adapter + ViewModel/Model
-> XML + Databinding.
Run Code Online (Sandbox Code Playgroud)
XML结构
LinearLayout (vertical)
-> Header (match_parent on width, wrap_content on height)
-> WebView (match_parent on width, wrap_content on height)
(Webview does not scroll and it scales with the contents.
the recyler view handles scrolling)
Run Code Online (Sandbox Code Playgroud)
默认情况下,所有Web视图的可见性都消失了,当用户第一次点击标题时,调用webview.loadDataWithBaseUrl()时会加载它应该加载的内容并打开可见性.webview缩放其高度以完全显示内容.当用户再次单击标题时,它会将可见性变为已消失,整个行将折叠为标题.再次单击先前展开的标题,我不必再次加载数据,而只是打开可见性.
一切都很有效,但对于这个非常讨厌的问题. https://nofile.io/f/UBCh5PO7Wv9/screencapture-1525973579493.mp4这是Google收件箱中的录音和我的应用程序有完全相同的问题.
当我点击标题进行扩展并在webview中加载内容时,一些webview会在下面展开,我的意思是标题保持不变,看起来内容加载在点击的标题下方.
但对于某些内容,webviews会向上扩展,这意味着它会推动单击的标题以展开内容.这意味着我在看内容的结尾而不是顶部.就像收件箱的这种情况一样,我正在查看电子邮件的结尾,但不是在电子邮件的顶部.
我在我分享的视频中复制了电子邮件的来源,并使用它们加载我的网页视图,这是我的发现.
基本上,如果A和B是webview的顶部和底部边缘,理想情况下A应该保持稳定,B应该增加向下推动它下面的recyclerView内容.但相反,当我从下向上扩展内容时,底线B保持稳定并且webview增加并推动标题和给定行上方的项目以及它导致查看结束时的恼人行为内容比谷歌收件箱中的顶部更好.
这是一个发生什么的gif - 当我点击紫色标题时,webview(粉红色)加载电子邮件.当我点击最后一个时,webview将在下面展开.但是当我点击最后一个时,它会向上扩展,然后向上推动标题.

有什么想法吗?救命?
谢谢
html android android-webview recycler-adapter android-recyclerview
我有滚动问题.我的意思是滚动速度很快,但在滚动完成之前看起来像是滞后.在这里我定义__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
我有RecyclerView一个LinearLayoutManager和Adapter:
@Override public int getItemViewType(int position) {
return position == 0? R.layout.header : R.layout.item;
}
Run Code Online (Sandbox Code Playgroud)
这是header.xml:
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
/>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是在我可以点击的地方找到一个洞.我尝试了很多组合以下属性无济于事:RecyclerViewRecyclerView
android:background="@android:color/transparent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"
Run Code Online (Sandbox Code Playgroud)
如何让列表中的第一个项目透明(允许触摸事件到它后面的任何东西),但让它仍然占据空间?
android android-layout android-listview recycler-adapter android-recyclerview
我想用延迟(20s)的animatoin创建聊天列表.在这段时间之后,每个项目都应该消失,同时淡出动画.
如果我RecyclerView不使用滚动就没问题.我重写适配器中的方法,一切正常.
@Override
public void onViewAttachedToWindow(final ViewHolder holder) {
if(holder.alpha == null) {
holder.alpha = ObjectAnimator.ofFloat(holder.itemView, View.ALPHA, 1f, 0f);
holder.alpha.setDuration(300);
holder.alpha.setStartDelay(20000);
holder.alpha.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
holder.profilePic.setEnabled(false);
holder.messageContainer.setEnabled(false);
if (items.size() > 0) {
items.remove(0);
notifyItemRemoved(0);
}
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
holder.alpha.start();
}
}
@Override
public void onViewDetachedFromWindow(ViewHolder holder) {
if(holder.alpha != null) {
holder.alpha.cancel();
holder.alpha …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我应该使用recyclerView并删除一些项目.
我想从中删除一些项目recyclerview,为此我在下面的代码中编写适配器:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private Context context;
private List<TvTonightResult> model;
public MyAdapter (Context context, List<TvTonightResult> model) {
this.context = context;
this.model = model;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_tv_tonight, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, final int position) {
holder.tvTonightTitle.setText(Html.fromHtml(model.get(position).getName()));
Glide.with(context)
.load(model.get(position).getImageUrl())
.placeholder(R.drawable.default_image)
.override(600, 900)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean …Run Code Online (Sandbox Code Playgroud)