我刚刚安装了新的SDK工具(Android L开发人员预览版),我正在尝试使用,RecyclerView但它似乎缺失了.
根据我的理解,我应该包括v7支持库,但我似乎无法做到这一点......
我似乎无法在SDK文件夹中找到v7库(我确实从SDK Manager安装了Android支持库).
先谢谢你.
如何在网格RecycleView中获取"向上滚动以加载更多"的不确定循环指示符?
该模式在那里描述:http://www.google.com/design/spec/components/progress-activity.html#progress-activity-behavior in"两阶段加载"和"示例2:向上滚动以加载更多"示例视频.
我正在尝试使用新的RecyclerView来实现这一点,但是我找不到一种"不太苛刻"的方式来做到这一点,首先是因为没有办法在网格中添加覆盖整行的页脚.有什么建议?
在我的片段中,我按以下方式设置GridLayout:
mRecycler.setLayoutManager(new GridLayoutManager(rootView.getContext(), 2));
所以,我只是想改变2的4,当用户旋转手机/平板电脑.我已经读过了onConfigurationChanged,我试图让它适用于我的情况,但它没有以正确的方式进行.当我旋转手机时,应用程序崩溃了......
你能告诉我如何解决这个问题吗?
以下是我找到解决方案的方法,该方法无法正常工作:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecycler.setLayoutManager(new GridLayoutManager(mContext, 2));
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mRecycler.setLayoutManager(new GridLayoutManager(mContext, 4));
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
android android-orientation android-gridlayout android-recyclerview
我想添加一些子视图(列表项),它们来自JSON格式的数据.每个子列表都在父列表项行下.如何RecyclerView为每个行项(包含子列表项的父项)填充它?
我尝试RecyclerView在RecyclerView父行中使用(用于填充子列表),但此处子视图不可见.
public class DigitizedPrescAdapter extends RecyclerView.Adapter<DigitizedPrescAdapter.ListItemViewHolder>{
private List<PrescriptionModal> prescriptionList;
MedicinesInPrescAdapter adapter;
public DigitizedPrescAdapter(List<PrescriptionModal> prescriptionListModal) {
if (prescriptionListModal == null) {
throw new IllegalArgumentException(
"PrescriptionList must not be null");
}
this.prescriptionList = prescriptionListModal;
}
@Override
public ListItemViewHolder onCreateViewHolder(
ViewGroup viewGroup, int viewType) {
View itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.item_row_digitised_request,
viewGroup,
false);
return new ListItemViewHolder(itemView);
}
@Override
public void onBindViewHolder(
ListItemViewHolder viewHolder, int position) {
PrescriptionModal model = prescriptionList.get(position);
viewHolder.prescnum.setText("Prescription "+ ++position);
viewHolder.prescNo.setText("Prescription: "+model.getPrescriptionID()); …Run Code Online (Sandbox Code Playgroud) 通过创建NestedScrollView,您可以将滚动视图放在另一个滚动视图中,只要这些视图正确实现NestedScrollingChild和NestedScrollingParent.
(这是一个不错的设计模式"Ian Lake(来自Google)实际上建议在RecyclerView这里放置一个nestedscrollview:plus.google.com/u/0/+AndroidDevelopers/posts/9kZ3SsXdT2T")
我想将RecyclerView放在NestedScrollView中,幸运的是RecyclerView实现了NestedScrollingChild,因此您可以将它放在NestedScrollView中.
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild
Run Code Online (Sandbox Code Playgroud)
我看过这些帖子:
如何在NestedScrollView中使用RecyclerView?
NestedScroll与NestedScrollView,RecyclerView(水平),在CoordinatorLayout内
但是大多数投票解决方案的问题是,它调用所有项目,RecyclerView例如,如果它是无尽的RecyclerView,当用户到达列表的末尾时,您想要发出网络请求,然后使用该解决方案RecyclerView重复调用服务器因为它会自动到达最后一项RecyclerView.
无论如何,如何设置参数,以便我可以放入RecyclerView内部NestedScrollView.(实际上我想将一个像framelayout或relativelayout这样的视图组作为nestedscrollview的单个childe然后我想将recyclelerview放在framelayout或relativelayout中)
当我放在RecyclerView里面NestedScrollView没有什么可以显示.
要创建示例项目,您可以使用cheesesquare并更改CheeseDetailActivity为具有RecyclerView.
虽然BNK的答案不正确,但BNK已经尝试了很多.所以我授予他赏金.还在寻找好的解决方案....
Recycler View Inconsistency检测到错误,在加载更多项目时快速滚动或滚动时出现错误.
FATAL EXCEPTION: main
Process: com.pratap.endlessrecyclerview, PID: 21997
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{56a082c position=40 id=-1, oldPos=39, pLpos:39 scrap [attachedScrap] tmpDetached no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4251)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4382)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2864)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1445)
at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:144)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:282)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Run Code Online (Sandbox Code Playgroud)
适配器
public class DataAdapter extends RecyclerView.Adapter {
private …Run Code Online (Sandbox Code Playgroud) 我在RecyclerView里面用NestedScrollView.我也设置setNestedScrollingEnabled为假recyclerview
支持较低的API
ViewCompat.setNestedScrollingEnabled(mRecyclerView, false);
现在!当用户滚动视图时,每件事似乎都没问题,但是!!! recyclerview中的视图不回收!和堆大小迅速增长!!
更新:RecyclerView布局管理器是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>
Run Code Online (Sandbox Code Playgroud)
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"
android:orientation="vertical" >
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scrollbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/nested_scrollbar_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<android.support.v7.widget.CardView
android:id="@+id/profileCardview"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 在使用ListView自定义适配器的旧代码中,我可以使用此代码获取项目.
Message msg = (Message) adapter.getItem(poistion);
Run Code Online (Sandbox Code Playgroud)
现在我正在实施RecyclerView.我如何从中获取物品RecyclerView.adapter?
好吧,我有一个带适配器的RecyclerView,一切都很好.ArrayList数据集中的项目将定期更新.因此,项目及其元素以及它们在列表中的位置会发生变化.无论什么时候发生,都可以通过简单的排序和手动调用这些方法来实现:
// swapping two items
Collections.swap(items, i, j);
itemsAdapter.notifyItemMoved(i, j);
// adding a new one
itemAdapter.notifyItemInserted(items.size());
// when updating valus
itemAdapter.notifyItemChanged(i);
Run Code Online (Sandbox Code Playgroud)
后者,是我痛苦的原因.每次更新项目时,都会触发一点"闪烁"动画.
我找到了几个解决方案:
// disabling all animations
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
// or
// setting the animation duration to zero,
recyclerView.getItemAnimator().setChangeDuration(0);
Run Code Online (Sandbox Code Playgroud)
但是当项目移动(被交换)时,这两个都会杀死动画.我只想覆盖一个动画并保持所有这些魔力.有办法做到这一点吗?如果它超越了ItemAnimator,有没有人有一个简单的例子?
提前致谢!
我正在尝试使用新的RecyvlerView适配器创建一个listView.我已经按照Android开发人员资源上的确切指南进行了操作.但这给了我一个奇怪的错误:指定的孩子已经有了父母.您必须首先在孩子的父母上调用removeView(). 我有最新的SDK.我还在gradle中定义依赖项.
MyActivity(主要活动):
public class MyActivity extends Activity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
// specify an adapter (see also next example)
mAdapter = new MyAdapter(new String[]{"Zain", …Run Code Online (Sandbox Code Playgroud)