Scrollview внутри переработчика не работает - PullRequest
0 голосов
/ 20 марта 2019

Я использую программу повторного просмотра с фрагментом.Один из моих фрагментов начинается новый фрагмент, который показывает профиль врача с изображением и длинный текст обо мне.Все работает нормально, кроме вертикальной прокрутки.Это совершенно учебная цель и я нуб на это.Пытаюсь узнать, как это работает.Я приложил фрагмент класса, адаптер и макет.Любой тип справки, предложения, исправления могут спасти меня.Заранее спасибо.

Адаптер

public class DoctorProfileAdapter extends RecyclerView.Adapter<DoctorProfileAdapter.DoctorProfileViewHolder> {

private Context mContext;
private List<Doctors> doctorsList;

public DoctorProfileAdapter(Context mContext, List<Doctors> doctorsList) {
    this.mContext = mContext;
    this.doctorsList = doctorsList;
}

@NonNull
@Override
public DoctorProfileViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.detail_doctor_profile, viewGroup, false);
    return new DoctorProfileViewHolder(view);
}

@Override
public void onBindViewHolder(final DoctorProfileViewHolder holder, final int position) {
    Doctors doctors = doctorsList.get(position);
    holder.name.setText(doctors.getName());
    holder.degree.setText(doctors.getDegree());
    holder.specialty.setText(doctors.getSpecialty());
    holder.departments.setText(doctors.getDepartments());
    holder.bio.setText(doctors.getBio());
    Glide.with(mContext).load(doctors.getThumbnail()).into(holder.thumbnail);
}

@Override
public int getItemCount() {
    return doctorsList.size();
}

public class DoctorProfileViewHolder extends RecyclerView.ViewHolder {
    public TextView name, degree, departments, specialty, bio;
    public ImageView thumbnail;
    public DoctorProfileViewHolder(View view) {
        super(view);
       name = view.findViewById(R.id.name);
       degree = view.findViewById(R.id.degree);
       departments = view.findViewById(R.id.department);
       specialty = view.findViewById(R.id.specialty);
       bio = view.findViewById(R.id.bio);
       thumbnail = view.findViewById(R.id.thumbnail);
    }
}
}

Фрагмент

public class DoctorProfileFragment extends Fragment {


private String ID, name, specialty, degree, thumbnail, departments, bio;

private DatabaseReference databaseReference;
private ValueEventListener listener;
private DoctorProfileAdapter adapter;
private List<Doctors> list;
public DoctorProfileFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivity().setTitle("Profile");
    Bundle bundle = getArguments();
    if (bundle != null) {
        ID = (String) bundle.getSerializable("id");
        name = (String) bundle.getSerializable("name");
        specialty = (String) bundle.getSerializable("specialty");
    }

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    databaseReference = FirebaseDatabase.getInstance().getReference();

    list = new ArrayList<>();
    View view = inflater.inflate(R.layout.blank_fragment, container, false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    adapter = new DoctorProfileAdapter(getContext(), list);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(adapter);
    asyncTask();
    return view;
}

private void asyncTask(){
    databaseReference = databaseReference.child("doctors").child(ID);
    listener = new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            degree = dataSnapshot.child("degree").getValue(String.class);
            departments = dataSnapshot.child("departments").getValue(String.class);
            bio = dataSnapshot.child("bio").getValue(String.class);
            thumbnail = dataSnapshot.child("thumbnail").getValue(String.class);
            Doctors doctors = new Doctors(name, degree, departments, specialty, thumbnail, bio);
            list.add(doctors);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    };
    databaseReference.addValueEventListener(listener);
}

}

Макет

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
    android:id="@+id/thumbnail"
    android:layout_width="match_parent"
    android:layout_height="250dp" />

<TextView
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginTop="@dimen/activity_horizontal_margin"
    android:textAppearance="@android:style/TextAppearance.Material.Headline"
    android:textSize="18sp"
    tools:text="This is me" />

<View
    android:layout_width="125dp"
    android:layout_height="2dp"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginTop="5dp"
    android:background="@color/colorPrimaryDark" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Degree:"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"/>
        <TextView
            android:id="@+id/degree"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_marginStart="@dimen/activity_horizontal_margin"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Specialty:"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin" />

        <TextView
            android:id="@+id/specialty"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="5dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Department:"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/department"
            android:layout_marginTop="5dp"
            android:layout_marginStart="@dimen/activity_horizontal_margin"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bio"/>
    </LinearLayout>
</ScrollView>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...