NestedScrollView仅适用于ViewPager的第一项,不适用于其他项

问题描述

我有一个具有2个视图的视图寻呼机,在每个视图中,我都有一个nestedScrollView,它是EditText的父级。 如我所愿,视图分页器中的第一个视图/项目会平滑滚动,但是如果我从未添加nestedScrollView,则会冻结另一个视图/项目!因此nestedScrollView仅适用于第一项。

项目:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.nestedScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <EditText
            android:id="@+id/edt_pager_leitner_info"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:enabled="false"
            android:inputType="textMultiLine"
            android:textColor="@color/darkGrey" />
    </androidx.core.widget.nestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

查看寻呼机适配器:

package com.yasinhajilou.dileit.view.adapter.viewpager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import com.yasinhajilou.dileit.R;

import java.util.ArrayList;
import java.util.List;

public class AddNewLeitnerViewPagerAdapter extends PagerAdapter {
    List<String> titles = new ArrayList<>();
    List<String> m@R_276_4045@ion = new ArrayList<>();

    @Override
    public int getCount() {
        return titles.size();
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container,int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager_leitner_info,container,false);
        view.setTag(titles.get(position));
        TextView textView = view.findViewById(R.id.edt_pager_leitner_info);
        textView.setText(m@R_276_404[email protected](position));
        container.addView(view);
        return view;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view,@NonNull Object object) {
        return view == object;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (titles.size() > 0)
            return titles.get(position);
        else return null;
    }

    public void addData(String title,String info) {
        titles.add(title);
        m@R_276_404[email protected](info);
        notifyDataSetChanged();
    }


}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)