Android RecyclerView中的Progressbar始终显示在顶部

Android RecyclerView中的Progressbar始终显示在顶部,android,android-recyclerview,Android,Android Recyclerview,我使用的是一个recyclerview,在这个recyclerview中我有一个cardview列表。内容是静态的,不会改变什么。当我将列表拖到顶部时,会出现一个进度条并停留在那里 如何解决这个问题。我在网上搜索过,没有找到相关的东西。谢谢你的回答 来自模拟器的照片:(注意中间的progressbar加载) RVAdapter.java public class RVAdapter extends RecyclerView.Adapter<RVAdapter.PersonViewHolde

我使用的是一个recyclerview,在这个recyclerview中我有一个cardview列表。内容是静态的,不会改变什么。当我将列表拖到顶部时,会出现一个进度条并停留在那里

如何解决这个问题。我在网上搜索过,没有找到相关的东西。谢谢你的回答

来自模拟器的照片:(注意中间的progressbar加载)

RVAdapter.java

public class RVAdapter extends RecyclerView.Adapter<RVAdapter.PersonViewHolder> {

    public static class PersonViewHolder extends RecyclerView.ViewHolder {
        CardView cv;
        TextView personName;
        TextView personAge;
        ImageView personPhoto;
        Button personbutton;

        PersonViewHolder(View itemView) {
            super(itemView);
            cv = (CardView)itemView.findViewById(R.id.cv);
            personName = (TextView)itemView.findViewById(R.id.person_name);
            personAge = (TextView)itemView.findViewById(R.id.person_age);
            personPhoto = (ImageView)itemView.findViewById(R.id.person_photo);
            personbutton=(Button)itemView.findViewById(R.id.imgbuttondownload);

        }
    }

    List<Person> persons;

    RVAdapter(List<Person> persons){
        this.persons = persons;
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
    }

    @Override
    public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        PersonViewHolder pvh = new PersonViewHolder(v);
        return pvh;
    }

    @Override
    public void onBindViewHolder(PersonViewHolder personViewHolder, final int i) {
        personViewHolder.personName.setText(persons.get(i).name);
        personViewHolder.personAge.setText(persons.get(i).age);
        personViewHolder.personPhoto.setImageResource(persons.get(i).photoId);
        personViewHolder.personPhoto.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                Context context=v.getContext();
                Intent intent=new Intent();
                switch (i){
                    case 0:
                        intent =  new Intent(context, Main4Activity.class);
                        context.startActivity(intent);
                        break;
                    case 1:
                        intent =  new Intent(context, Main4Activity.class);
                        context.startActivity(intent);
                        break;
                    case 2:
                        intent =  new Intent(context, Main4Activity.class);
                        context.startActivity(intent);
                        break;
                    case 3:
                        intent =  new Intent(context, Main4Activity.class);
                        context.startActivity(intent);
                        break;
                }
            }
        });

        personViewHolder.personbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Person person = persons.get(i);
                Context context=v.getContext();
                String url = person.url;

                DownloadManager manager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                request.setDescription(person.title);
                request.setTitle(person.title);

                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(
                        DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "file"+person.title+".mp4");
                manager.enqueue(request);
            }
        });
    }

    @Override
    public int getItemCount() {
        return persons.size();
    }
}
公共类RVAdapter扩展了RecyclerView.Adapter{ 公共静态类PersonViewHolder扩展了RecyclerView.ViewHolder{ 卡德维尤简历; TextView人名; 文本视图人物; ImageView个人照片; 按钮个人按钮; PersonViewHolder(查看项目视图){ 超级(项目视图); cv=(cardwiew)itemView.findviewbyd(R.id.cv); personName=(TextView)itemView.findViewById(R.id.person\u name); personAge=(TextView)itemView.findViewById(R.id.person\u age); personPhoto=(ImageView)itemView.findViewById(R.id.person\u photo); personbutton=(按钮)itemView.findViewById(R.id.imgbuttondownload); } } 列出人员名单; RVAdapter(列出人员){ 这个人=人; } @凌驾 附加ToRecyclerView(RecyclerView RecyclerView)上的公共无效{ super.onAttachedToRecyclerView(recyclerView); } @凌驾 public PersonViewHolder onCreateViewHolder(视图组视图组,int i){ 视图v=LayoutInflater.from(viewGroup.getContext()).flate(R.layout.item,viewGroup,false); PersonViewHolder pvh=新PersonViewHolder(v); 返回pvh; } @凌驾 BindViewHolder上的公共无效(PersonViewHolder PersonViewHolder,最终int i){ personViewHolder.personName.setText(persons.get(i.name)); personViewHolder.personAge.setText(persons.get(i.age)); personViewHolder.personPhoto.setImageResource(persons.get(i.photoId)); personViewHolder.personPhoto.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ Context=v.getContext(); 意图=新意图(); 开关(一){ 案例0: 意图=新意图(上下文,Main4Activity.class); 背景。开始触觉(意图); 打破 案例1: 意图=新意图(上下文,Main4Activity.class); 背景。开始触觉(意图); 打破 案例2: 意图=新意图(上下文,Main4Activity.class); 背景。开始触觉(意图); 打破 案例3: 意图=新意图(上下文,Main4Activity.class); 背景。开始触觉(意图); 打破 } } }); personViewHolder.personbutton.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图v){ Person=persons.get(i); Context=v.getContext(); 字符串url=person.url; DownloadManager=(DownloadManager)context.getSystemService(context.DOWNLOAD\u服务); DownloadManager.Request=newdownloadmanager.Request(Uri.parse(url)); 请求.设置描述(个人.职务); 请求.setTitle(person.title); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY\u VISIBLE\u NOTIFY\u COMPLETED); request.setDestinationNexternalPublicDir(Environment.DIRECTORY_下载,“文件”+person.title+“.mp4”); 排队(请求); } }); } @凌驾 public int getItemCount(){ 返回人。大小(); } } MainActivity.java

 super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        rv=(RecyclerView)findViewById(R.id.rv);
        ActivityCompat.requestPermissions(this, new String[]{
                Manifest.permission.WRITE_EXTERNAL_STORAGE
        }, REQUEST_CODE);

        LinearLayoutManager llm = new LinearLayoutManager(this);
        rv.setLayoutManager(llm);
        rv.setHasFixedSize(true);
        initializeData();
        initializeAdapter();
}

  private void initializeData(){
        persons = new ArrayList<>();
        persons.add(new Person("How to perform a staphylectomy | Surgical correction of RLN", "10:07", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","YESddddd"));
        persons.add(new Person("How to perfom a clinical examination", "07:03", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","gvjhkllklkj2bb"));
        persons.add(new Person("How to perform a radiographic examination", "03:50", R.drawable.chirurgie,"https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","nadaaa"));


    }

    private void initializeAdapter(){
        RVAdapter adapter = new RVAdapter(persons);
        rv.setAdapter(adapter);
    }
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
rv=(RecyclerView)findViewById(R.id.rv);
ActivityCompat.requestPermissions(此,新字符串[]){
Manifest.permission.WRITE\u外部存储
},请求代码);
LinearLayoutManager llm=新的LinearLayoutManager(本);
rv.setLayoutManager(llm);
rv.setHasFixedSize(真);
初始化数据();
初始化为apter();
}
private void initializeData(){
persons=newarraylist();
新增人员(“如何进行镫骨切除术| RLN的外科矫正”,“10:07”,R.drawable.Chirugerie,”https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1","是","是",;
新增(新人员(“如何进行临床检查”,“07:03”,R.drawable.Chirugerie,”https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1“,“gvjhkllkkj2bb”);
新增人员(“如何进行射线照相检查”,“03:50”,R.drawable.chirurgie,”https://drive.google.com/uc?export=download&id=1mxYNzdeCtp7mP5Jv0gqESTgIFa9pGhF1“,”nadaaa“);
}
private void initializedapter(){
RVAdapter适配器=新的RVAdapter(人);
rv.设置适配器(适配器);
}
activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/activity_main3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".MainActivity"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include layout="@layout/app_bar_menu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="right"
        android:id="@+id/nv3"
        android:background="@android:color/white"
        app:headerLayout="@layout/navigation_header"

        >

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

App_bar_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:background="@color/redcolor"
        android:layout_height="192dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimaryDark"
            app:expandedTitleMarginStart="30dp"
            app:expandedTitleMarginEnd="2dp"
            app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
            app:expandedTitleTextAppearance="@style/ExpandedAppBar"
            >

            <ImageView
                android:id="@+id/imagetoolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />


</android.support.design.widget.CoordinatorLayout>

content_main.xml

<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeToRefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

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

    </android.support.v7.widget.RecyclerView>


</android.support.v4.widget.SwipeRefreshLayout>

您有一个SwiperFreshLayout
通过
findViewById
找到它,然后调用

swipeRefreshLayout.setRefreshing(false);
swipeRefreshLayout.setEnabled(false);

这个问题太狭隘,难以理解。我的意思是,用一些示例代码详细解释如何显示装载指示器。那么只有成员才能提供帮助。正如你在欧洲货币联盟中看到的那样