RecyclerView不滚动至底部 [英] RecyclerView not scrolling to the bottom

查看:234
本文介绍了RecyclerView不滚动至底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着recyclerview指导方针和建立一个我制作的应用程序,但它不滚动到底出于某种原因。我与谷歌的code片段,以及其他code段相比,它在线看不出区别。我已经发布的图片,我使用的是code。我使用的标签,因此recyclerview填充在一个片段。

应用程序看起来像什么:

http://imgur.com/H5uOLFR

适配器类:

 公共类MyAdapter扩展RecyclerView.Adapter< MyAdapter.ViewHolder> {
私人列表<组>组;//提供对每个数据项意见的参考
//复杂的数据也有可能需要每个项目的多个视图,并
//您提供的所有数据项在视图中持有人的意见访问
公共类ViewHolder扩展RecyclerView.ViewHolder {
    //每个数据项仅仅是在这种情况下,串
    公共TextView的组名;
    公众的TextView groupDate;
    公众的TextView groupLocation;
    公共TextView的类名;    公共ViewHolder(视图v){
        超级(五);
        组名=(的TextView)v.findViewById(R.id.groupName);
        groupDate =(TextView中)v.findViewById(R.id.groupDate);
        groupLocation =(TextView中)v.findViewById(R.id.groupLocation);
        的className =(TextView中)v.findViewById(R.id.className);
    }
}/ *
 * TODO:完成此方法
 * /
公共无效添加(INT位置,串项){    notifyItemInserted(位置);
}公共无效删除(字符串项){
    INT位置= groups.indexOf(项目);
    groups.remove(位置);
    notifyItemRemoved(位置);
}//提供一个合适的构造函数(依赖于一种数据集)
公共MyAdapter(列表<组> groupsList){
    组= groupsList;
    Log.d(TEST,组数:+
            Integer.toString(groups.size()));
}//创建新的视图(由布局管理器调用)
@覆盖
公共MyAdapter.ViewHolder onCreateViewHolder(ViewGroup中父母,
                                               INT viewType){
    //创建一个新视图
    视图V = LayoutInflater.from(parent.getContext())膨胀(R.layout.group_view,父母,假的)。
    //设置视图的大小,边距,填充和布局参数
    ViewHolder VH =新ViewHolder(ⅴ);
    返回VH;
}//替换视图的内容(由布局管理器调用)
@覆盖
公共无效onBindViewHolder(ViewHolder持有人,INT位置){
    // - 在这个位置从数据集中获取元素
    // - 与元素替换视图的内容
    最后组组= groups.get(位置);
// holder.groupName.setText(group.getName());
    holder.groupName.setText(group.getName());
    holder.groupDate.setText(group.getFormattedDate());
    holder.groupLocation.setText(group.getLocation());
    holder.className.setText(group.getParent()的getName());
}//返回数据集的大小(由布局管理器调用)
@覆盖
公众诠释getItemCount(){
    返回groups.size();
}}

分片类:

 公共类groupsFragment扩展片段实现GroupLeaver,的Grou $ P $ {ptriever
私人RecyclerView RV;
私人列表<组>组;
私人ProgressDialog progressDialog;@覆盖
公共无效的onCreate(捆绑savedInstance){
    super.onCreate(savedInstance);
    Log.d(TEST,输入的onCreate);
}@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
    。AppMain.getController()retrieveGroups(groupsFragment.this);
    Log.d(TEST,输入onCreateView);
    查看rootView = inflater.inflate(R.layout.groups_fragment,集装箱,FALSE);    RV =(RecyclerView)rootView.findViewById(R.id.recyclerView);    rv.setLayoutManager(新LinearLayoutManager(getActivity()));    Log.d(TEST,LIST的大小:+ Integer.toString(groups.size()));
    MyAdapter适配器=新MyAdapter(组);
    rv.setAdapter(适配器);    返回rootView;
}@覆盖
公共无效onMyGroupsFound(列表<组>组){
    Log.d(TEST,输入onMyGroupsFound);
    Logg.info(this.getClass(),发现%d个团体会员%S,groups.size(),User.getCurrentUser()getDisplayName());
    this.groups =组;
}@覆盖
公共无效onGroupLeft(集团oldGroup){}@覆盖
公共无效onGroupLeftFailed(集团组,ParseException的E){}
}

XML的布局为recyclerview:

 <?XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
>< android.support.v7.widget.RecyclerView
    机器人:ID =@ + ID / recyclerView
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:分=@空/>< /&的FrameLayout GT;

XML的布局为recyclerview项目:

 <?XML版本=1.0编码=UTF-8&GT?;<的FrameLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
><的LinearLayout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:填充=16DP
    机器人:方向=横向>    <的LinearLayout
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =0dp
        机器人:layout_weight =3
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID /组名
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=组名
            />        <的TextView
            机器人:ID =@ + ID / groupDate
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=组日期
            />        <的TextView
            机器人:ID =@ + ID / groupLocation
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文字=集团的位置
            />
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =0dp
        机器人:layout_weight =1
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID /类名
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_gravity =中心
            机器人:重力=右
            机器人:文字=类名
            />
    < / LinearLayout中>< / LinearLayout中>
< /&的FrameLayout GT;


解决方案

感谢大家谁回答,但原来的问题是recyclerview的版本我进行编译。

previously我编写本:
编译com.android.support:recyclerview-v7:22.0.0

不过,我改成了这一点,它的工作。
编译com.android.support:recyclerview-v7:22.2.0

贷@roi的答案divon:<一href=\"http://stackoverflow.com/questions/30546812/coordinatorlayout-with-recyclerview-collapsingtoolbarlayout\">CoordinatorLayout与RecyclerView&安培; CollapsingToolbarLayout

I followed the recyclerview guidelines and built one for the app I am making, but it does not scroll to the bottom for some reason. I compared it with google code snippets, as well as other code snippets online and can't see the difference. I have posted a picture and the code I am using. I am using tabs, therefore the recyclerview is populated in a fragment.

What the app looks like:

http://imgur.com/H5uOLFR

the adapter class:

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<Group> groups;

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
    // each data item is just a string in this case
    public TextView groupName;
    public TextView groupDate;
    public TextView groupLocation;
    public TextView className;

    public ViewHolder(View v) {
        super(v);
        groupName = (TextView) v.findViewById(R.id.groupName);
        groupDate = (TextView) v.findViewById(R.id.groupDate);
        groupLocation = (TextView) v.findViewById(R.id.groupLocation);
        className = (TextView) v.findViewById(R.id.className);
    }
}

/*
 * TODO: finish this method
 */
public void add(int position, String item) {

    notifyItemInserted(position);
}

public void remove(String item) {
    int position = groups.indexOf(item);
    groups.remove(position);
    notifyItemRemoved(position);
}

// Provide a suitable constructor (depends on the kind of dataset)
public MyAdapter(List<Group> groupsList) {
    groups = groupsList;
    Log.d("TEST", "Number of Groups: " +
            Integer.toString(groups.size()));
}

// Create new views (invoked by the layout manager)
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
    // create a new view
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.group_view, parent, false);
    // set the view's size, margins, paddings and layout parameters
    ViewHolder vh = new ViewHolder(v);
    return vh;
}

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    final Group group = groups.get(position);
//      holder.groupName.setText(group.getName());
    holder.groupName.setText(group.getName());
    holder.groupDate.setText(group.getFormattedDate());
    holder.groupLocation.setText(group.getLocation());
    holder.className.setText(group.getParent().getName());
}

// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
    return groups.size();
}

}

The Fragment class:

public class groupsFragment extends Fragment implements GroupLeaver, GroupRetriever {
private RecyclerView rv;
private List<Group> groups;
private ProgressDialog progressDialog;

@Override
public void onCreate(Bundle savedInstance){
    super.onCreate(savedInstance);
    Log.d("TEST", "Entered onCreate");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    AppMain.getController().retrieveGroups(groupsFragment.this);
    Log.d("TEST", "Entered onCreateView");
    View rootView =  inflater.inflate(R.layout.groups_fragment, container, false);

    rv = (RecyclerView) rootView.findViewById(R.id.recyclerView);

    rv.setLayoutManager(new LinearLayoutManager(getActivity()));

    Log.d("TEST", "Size of LIST: " + Integer.toString(groups.size()));
    MyAdapter adapter = new MyAdapter(groups);
    rv.setAdapter(adapter);

    return rootView;
}

@Override
public void onMyGroupsFound(List<Group> groups) {
    Log.d("TEST", "Entered onMyGroupsFound");
    Logg.info(this.getClass(), "Found %d groups for member %s", groups.size(), User.getCurrentUser().getDisplayName());
    this.groups = groups;
}

@Override
public void onGroupLeft(Group oldGroup) {

}

@Override
public void onGroupLeftFailed(Group group, ParseException e) {

}
}

The xml layout for the recyclerview:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@null"/>

</FrameLayout>

The xml layout for the recyclerview items:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="3"
        android:orientation="vertical">

        <TextView
            android:id="@+id/groupName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Group Name"
            />

        <TextView
            android:id="@+id/groupDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Group Date"
            />

        <TextView
            android:id="@+id/groupLocation"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Group Location"
            />
    </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/className"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="right"
            android:text="Class Name"
            />
    </LinearLayout>

</LinearLayout>
</FrameLayout>

解决方案

Thanks to everyone who responded, but turns out the problem was the version of recyclerview I was compiling.

Previously I was compiling this: compile 'com.android.support:recyclerview-v7:22.0.0'

But I changed it to this and it worked. compile 'com.android.support:recyclerview-v7:22.2.0'

Credits to @roi divon for the answer: CoordinatorLayout with RecyclerView & CollapsingToolbarLayout

这篇关于RecyclerView不滚动至底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆