- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 fragment ,里面有一个 recyclerview (GridlayoutManager)。 recyclerview 中的项目并不复杂或有图像,但在向下滚动 recyclerview 时滞后(在 Nexus 5 上测试)。我将 hasFixedSize 和 hasStableIds 设置为 true有谁知道为什么会这样?提前致谢。
fragment
public class EditTimetableFragment extends Fragment implements TimetableRecyclerViewAdapter.ClickListener {
public EditTimetableFragment() {}
DAO dao;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
RecyclerView recyclerViewTimetable;
Spinner spinnerSubject;
TimetableRecyclerViewAdapter timetableRecyclerViewAdapter;
TaskSubjectSpinnerAdapter taskSubjectSpinnerAdapter;
List<Subject> subjectList;
List<Timetable> timetableList;
FloatingActionButton fabAddSubject;
boolean saturday, sunday;
int dayLength, hourLength;
TextView textViewSa, textViewSu;
LinearLayout week, linearLayout;
View view;
public View getView() {
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this
dao = new DAO(getActivity());
getTimetableSettings();
subjectList = dao.getAllSubjectsAlphabetical();
timetableList = dao.getTimetableList(dayLength, saturday, sunday);
view = inflater.inflate(R.layout.fragment_edit_timtable, container, false);
Toast.makeText(getActivity(),"onCreateView",Toast.LENGTH_SHORT).show();
linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout);
fabAddSubject = (FloatingActionButton) view.findViewById(R.id.fabAddSubject);
fabAddSubject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), AddSubjectActivity.class));
}
});
textViewSa = (TextView) view.findViewById(R.id.textViewSa);
textViewSu = (TextView) view.findViewById(R.id.textViewSu);
week = (LinearLayout) view.findViewById(R.id.week);
setRecyclerViewTimetable(view);
setSpinnerSubject(view);
if (saturday && sunday) {
textViewSa.setVisibility(View.VISIBLE);
textViewSu.setVisibility(View.VISIBLE);
} else if (saturday && !sunday) {
textViewSa.setVisibility(View.VISIBLE);
textViewSu.setVisibility(View.GONE);
} else if (!saturday && sunday) {
textViewSa.setVisibility(View.GONE);
textViewSu.setVisibility(View.VISIBLE);
} else if (!saturday && !sunday) {
textViewSa.setVisibility(View.GONE);
textViewSu.setVisibility(View.GONE);
}
return view;
}
public void setRecyclerViewTimetable(View view) {
recyclerViewTimetable = (RecyclerView) view.findViewById(R.id.recyclerViewTimetable);
timetableRecyclerViewAdapter =
new TimetableRecyclerViewAdapter(
getActivity(), true, saturday, sunday, dayLength);
timetableRecyclerViewAdapter.setClickListener(this);
recyclerViewTimetable.setHasFixedSize(true);
recyclerViewTimetable.setLayoutManager(
new GridLayoutManager(getActivity(), dayCount()));
recyclerViewTimetable.setAdapter(timetableRecyclerViewAdapter);
}
private void setSpinnerSubject(View view) {
spinnerSubject = (Spinner) view.findViewById(R.id.spinnerSubject);
taskSubjectSpinnerAdapter = new TaskSubjectSpinnerAdapter(getActivity(), subjectList);
spinnerSubject.setAdapter(taskSubjectSpinnerAdapter);
}
private void getTimetableSettings() {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
editor = sharedPreferences.edit();
saturday = sharedPreferences.getBoolean(getResources().getString(R.string.settingSaturday), false);
sunday = sharedPreferences.getBoolean(getResources().getString(R.string.settingSunday), false);
dayLength = sharedPreferences.getInt(getResources().getString(R.string.settingDay), 10);
hourLength = sharedPreferences.getInt(getResources().getString(R.string.settingHour), 45);
//Toast.makeText(getActivity(), "dayCount=" + dayCount() + " Sat" + saturday + " Sun" + sunday, Toast.LENGTH_SHORT).show();
}
private int dayCount() {
int a = 0;
if (saturday && sunday) {
a = 7;
} else if (saturday && !sunday) {
a = 6;
} else if (!saturday && sunday) {
a = 6;
} else if (!saturday && !sunday) {
a = 5;
}
return a;
}
@Override
public void onResume() {
super.onResume();
getTimetableSettings();
subjectList = dao.getAllSubjectsAlphabetical();
timetableList = dao.getTimetableList(dayLength, saturday, sunday);
setSpinnerSubject(view);
setRecyclerViewTimetable(view);
if (saturday && sunday) {
textViewSa.setVisibility(View.VISIBLE);
textViewSu.setVisibility(View.VISIBLE);
} else if (saturday && !sunday) {
textViewSa.setVisibility(View.VISIBLE);
textViewSu.setVisibility(View.GONE);
} else if (!saturday && sunday) {
textViewSa.setVisibility(View.GONE);
textViewSu.setVisibility(View.VISIBLE);
} else if (!saturday && !sunday) {
textViewSa.setVisibility(View.GONE);
textViewSu.setVisibility(View.GONE);
}
}
@Override
public void itemClicked(View v, int position) {
timetableList = dao.getTimetableList(dayLength, saturday, sunday);
subjectList = dao.getAllSubjectsAlphabetical();
if (!subjectList.isEmpty()) {
Timetable timetableOld = timetableList.get(position);
Subject subject = subjectList.get(spinnerSubject.getSelectedItemPosition());
Timetable timetableNew;
if (timetableOld.getSubjectId().equals(subject.getId())) {
timetableNew = dao.updateTimetable(timetableOld.getX(), timetableOld.getY(), "");
} else {
timetableNew = dao.updateTimetable(timetableOld.getX(), timetableOld.getY(), subject.getId());
}
timetableRecyclerViewAdapter.update(timetableNew, position);
} else {
Snackbar.make(linearLayout, R.string.AddSubjectsQuestion, Snackbar.LENGTH_LONG)
.setAction(R.string.Yes, new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), AddSubjectActivity.class));
}
}).show();
}
}
}
布局
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
tools:context="com.feserware.learn.Timetable.EditTimetableActivity">
<include
android:id="@+id/week"
layout="@layout/week" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewTimetable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/linearLayout"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal"
android:background="@color/primary"
android:minHeight="?attr/actionBarSize"
android:orientation="horizontal"
android:padding="19dp">
<Spinner
android:id="@+id/spinnerSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fabAddSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_input_add"
android:tint="#fff"
app:fab_type="mini" />
</RelativeLayout>
适配器
public class TimetableRecyclerViewAdapter
extends RecyclerView.Adapter
<TimetableRecyclerViewAdapter.timetableViewHolder> {
List<Timetable> timetableList;
Context context;
ClickListener clickListener;
LayoutInflater inflater;
DAO dao;
boolean showHour, saturday, sunday;
int hours;
public TimetableRecyclerViewAdapter(Context context, boolean showHour, boolean saturday, boolean sunday, int hours) {
this.inflater = LayoutInflater.from(context);
this.context = context;
dao = new DAO(context);
this.timetableList = dao.getTimetableList(hours, saturday, sunday);
this.showHour = showHour;
this.saturday = saturday;
this.sunday = sunday;
this.hours = hours;
setHasStableIds(true);
}
@Override
public timetableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.item_timetable, parent, false);
timetableViewHolder holder = new timetableViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(timetableViewHolder holder, int position) {
Timetable timetable = timetableList.get(position);
Subject subject = dao.getSubject(timetable.getSubjectId());
holder.textViewTimetableSubjectShort.setText("");
holder.textViewTimetableRoom.setText("");
if (subject == null) {
dao.updateTimetable(timetable.getX(), timetable.getY(), "");
}
if (timetable.getSubjectId().isEmpty()) {
holder.textViewTimetableSubjectShort.setText(timetable.getY() + "");
holder.linearLayoutBackground.setBackgroundColor(Color.WHITE);
} else {
holder.textViewTimetableSubjectShort.setText(subject.getSubjectShort());
holder.textViewTimetableRoom.setText(subject.getRoom());
holder.linearLayoutBackground.setBackgroundColor(subject.getColor());
}
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return timetableList.size();
}
public void setClickListener(ClickListener clickListener) {
this.clickListener = clickListener;
}
class timetableViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textViewTimetableSubjectShort, textViewTimetableRoom;
LinearLayout linearLayoutBackground;
public timetableViewHolder(View itemView) {
super(itemView);
textViewTimetableSubjectShort = (TextView) itemView.findViewById(R.id.textViewSubjectShort);
textViewTimetableRoom = (TextView) itemView.findViewById(R.id.textViewSubjectRoom);
linearLayoutBackground = (LinearLayout) itemView.findViewById(R.id.linearLayoutBackground);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (clickListener != null) {
clickListener.itemClicked(v, getLayoutPosition());
}
}
}
public interface ClickListener {
void itemClicked(View v, int postion);
}
public void update(Timetable timetable, int pos) {
timetableList.set(pos, timetable);
notifyItemChanged(pos);
}
}
日志猫
09-11 17:48:32.098 31535-31535/com.feserware.learn D/TimetableRecyclerVH﹕ Constructor
09-11 17:48:32.148 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.148 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.156 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 0
09-11 17:48:32.159 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.159 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.165 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 1
09-11 17:48:32.169 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.170 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.175 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 2
09-11 17:48:32.178 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.178 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.184 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 3
09-11 17:48:32.188 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.189 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.195 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 4
09-11 17:48:32.203 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.203 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.209 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 5
09-11 17:48:32.211 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.211 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.217 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 6
09-11 17:48:32.222 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.222 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.228 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 7
09-11 17:48:32.231 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.231 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.237 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 8
09-11 17:48:32.239 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.239 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.246 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 9
09-11 17:48:32.252 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.252 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.259 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 10
09-11 17:48:32.261 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.261 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.264 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 11
09-11 17:48:32.266 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.266 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.269 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 12
09-11 17:48:32.272 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.272 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.276 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 13
09-11 17:48:32.278 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.278 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.281 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 14
09-11 17:48:32.288 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.288 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.292 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 15
09-11 17:48:32.320 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.320 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.326 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 16
09-11 17:48:32.328 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.328 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.333 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 17
09-11 17:48:32.335 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.335 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.342 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 18
09-11 17:48:32.344 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.344 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.349 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 19
09-11 17:48:32.358 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.358 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.367 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 20
09-11 17:48:32.370 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.370 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.376 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 21
09-11 17:48:32.378 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.378 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.383 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 22
09-11 17:48:32.385 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.385 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.393 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 23
09-11 17:48:32.395 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.395 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.400 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 24
09-11 17:48:32.422 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.422 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.430 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 25
09-11 17:48:32.432 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.432 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.437 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 26
09-11 17:48:32.443 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.443 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.450 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 27
09-11 17:48:32.456 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.457 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.464 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 28
09-11 17:48:32.466 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:32.466 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:32.469 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 29
09-11 17:48:32.631 31535-31589/com.feserware.learn D/OpenGLRenderer﹕ endAllStagingAnimators on 0xa1b9ed00 (RippleDrawable) with handle 0xa188dfb0
09-11 17:48:35.406 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.406 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.410 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 30
09-11 17:48:35.429 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.429 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.432 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 31
09-11 17:48:35.446 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.446 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.450 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 32
09-11 17:48:35.464 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.464 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.469 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 33
09-11 17:48:35.482 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.483 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.487 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 34
09-11 17:48:35.505 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 35
09-11 17:48:35.509 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 36
09-11 17:48:35.524 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 37
09-11 17:48:35.538 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 38
09-11 17:48:35.552 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.552 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.557 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 39
09-11 17:48:35.575 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 40
09-11 17:48:35.580 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 41
09-11 17:48:35.596 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 42
09-11 17:48:35.611 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 43
09-11 17:48:35.632 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.632 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.637 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 44
09-11 17:48:35.654 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 45
09-11 17:48:35.668 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 46
09-11 17:48:35.682 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 47
09-11 17:48:35.696 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 48
09-11 17:48:35.711 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 49
09-11 17:48:35.764 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 50
09-11 17:48:35.781 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 51
09-11 17:48:35.797 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 52
09-11 17:48:35.813 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 53
09-11 17:48:35.827 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:35.827 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:35.831 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 54
09-11 17:48:35.863 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 55
09-11 17:48:35.912 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 56
09-11 17:48:35.926 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 57
09-11 17:48:35.943 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 58
09-11 17:48:35.962 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 59
09-11 17:48:35.981 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 60
09-11 17:48:35.999 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 61
09-11 17:48:36.016 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 62
09-11 17:48:36.037 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 63
09-11 17:48:36.053 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:36.053 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:36.057 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 64
09-11 17:48:36.077 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 65
09-11 17:48:36.091 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 66
09-11 17:48:36.108 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 67
09-11 17:48:36.125 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 68
09-11 17:48:36.143 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 69
09-11 17:48:36.161 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 70
09-11 17:48:36.176 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 71
09-11 17:48:36.191 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 72
09-11 17:48:36.206 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 73
09-11 17:48:36.228 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:36.228 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:36.232 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 74
09-11 17:48:36.249 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 75
09-11 17:48:36.264 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 76
09-11 17:48:36.278 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 77
09-11 17:48:36.293 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 78
09-11 17:48:36.306 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 79
09-11 17:48:36.324 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 80
09-11 17:48:36.342 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 81
09-11 17:48:36.357 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 82
09-11 17:48:36.371 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 83
09-11 17:48:36.383 31535-31535/com.feserware.learn D/TtRecycler﹕ timetableViewHolder
09-11 17:48:36.383 31535-31535/com.feserware.learn D/TtRecycler﹕ onCreateViewHolder
09-11 17:48:36.387 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 84
09-11 17:48:36.410 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 85
09-11 17:48:36.424 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 86
09-11 17:48:36.438 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 87
09-11 17:48:36.454 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 88
09-11 17:48:36.470 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 89
09-11 17:48:36.498 31535-31535/com.feserware.learn I/Choreographer﹕ Skipped 31 frames! The application may be doing too much work on its main thread.
09-11 17:48:36.539 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 90
09-11 17:48:36.556 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 91
09-11 17:48:36.571 31535-31535/com.feserware.learn D/TtRecycler﹕ onBindViewHolder | 92
最佳答案
好吧,我不知道你的代码到底出了什么问题,但我能做的是为你提供一个我使用的示例回收程序代码,相信你可以与你的代码进行比较,找出你可能出错的地方,它是一个可扩展的回收器, child 有一个带有图像的水平 ListView ,我没有遇到滞后我使用华为 Y300,那是一个低端手机,我选择那个手机是因为我知道我的代码是否可以很好地工作然后它适用于大多数手机,所以这是我的可扩展回收器适配器的示例,我的代码虽然存在内存使用问题,但在加载大约 20 个项目(每个项目有 5 张图片)后,它会增加到大约 20mb
public class ExpandableCategoryAdapter extends ExpandableRecyclerAdapter<CategoryParentViewHolder, CategoryChildViewHolder> {
/**
* Primary constructor. Sets up {@link #mParentItemList} and {@link #mItemList}.
* <p>
* Changes to {@link #mParentItemList} should be made through add/remove methods in
* {@link ExpandableRecyclerAdapter}
*
* @param parentItemList List of all {@link ParentListItem} objects to be
* displayed in the RecyclerView that this
* adapter is linked to
*/
private LayoutInflater mInflater;
private CategoryChildViewHolder childViewHolder;
private Context context;
private UserDataHolderDB db;
//click onitemlisteners
//I chose these because they
//readily provide the IDS/position
private OnItemClickListener addItemListener;
private OnItemClickListener gotoListener;
public ExpandableCategoryAdapter(OnItemClickListener addItemListener, OnItemClickListener gotoListener,Context context, ArrayList<ExpandableCategoryItem> parentItemList) {
super(parentItemList);
this.addItemListener = addItemListener;
this.gotoListener = gotoListener;
this.context = context;
mInflater = LayoutInflater.from(context);
db = new UserDataHolderDB(context);
}
//ofcos the interface to implement from
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
@Override
public CategoryParentViewHolder onCreateParentViewHolder(ViewGroup parentViewGroup) {
View view = mInflater.inflate(R.layout.parent_category, parentViewGroup, false);
return new CategoryParentViewHolder(view);
}
@Override
public CategoryChildViewHolder onCreateChildViewHolder(ViewGroup childViewGroup) {
View view = mInflater.inflate(R.layout.cloth_min_adapter, childViewGroup, false);
return new CategoryChildViewHolder(view);
}
@Override
public void onBindParentViewHolder(CategoryParentViewHolder parentViewHolder, int position, ParentListItem parentListItem) {
parentViewHolder.setIsRecyclable(true);
ExpandableCategoryItem parentData = (ExpandableCategoryItem) parentListItem;
parentViewHolder.mCrimeTitleTextView.setText(parentData.getmDescription());
try {
System.err.println("Palette value: " + parentData.getmSideBarColor());
if (parentData.getmSideBarColor() != null) {
parentViewHolder.mSideBar.setBackgroundColor(Integer.parseInt(parentData.getmSideBarColor()));
parentViewHolder.mSideBar.invalidate();
}
}catch (Exception e)
{
e.printStackTrace();
System.err.println("Palette value could not be decoded");
}
if(!parentViewHolder.isExpanded())
{
try{
if(childViewHolder.linearLayout != null) {
childViewHolder.linearLayout.removeAllViews();
if(parentData.getmSideBarColor() != null)
{
if(parentData.getmSideBarColor().isEmpty())
{
}
}
// parentViewHolder.mSideBar.getBackground() =
}
}catch (Exception e)
{
e.printStackTrace();
}
//trash child to save memory
}
try {
//reduce bitmap size to save on memory
Bitmap bitmap = BitmapFactory.decodeFile(parentData.getmCategoryImgPath());
bitmap = ResizeImage.getResizedBitmap(bitmap, 100, 100);
parentViewHolder.mCategoryImage.setImageBitmap(bitmap);
}catch (Exception e)
{
e.printStackTrace();
}
/
System.err.println("Parent ID"+parentData.getId());
System.err.println("Parent Description at Given ID: "+parentData.getmDescription());
parentViewHolder.mItemsShow.setText(db.categoryItemsNumber(parentData.getId()));
}
@Override
public void onBindChildViewHolder(CategoryChildViewHolder childViewHolder, int position, Object childListItem) {
//Button being assigned the Listener
childViewHolder.gotTo.setOnClickListener(v -> gotoListener.onItemClick(v, position));
childViewHolder.addNewItem.setOnClickListener(v -> addItemListener.onItemClick(v, position));
ChildItem data = (ChildItem) childListItem;
this.childViewHolder = childViewHolder;
int rootViewController = 0;
try {
childViewHolder.linearLayout.removeAllViews();
}catch (Exception w)
{
w.printStackTrace();
}
if(data.getImgUri() != null) {
for (String item : data.getImgUri()) {
try {
//stop adding images we are past our limit
if (rootViewController != 5) {
if(item.equals("") || !item.isEmpty()) {
Bitmap bitmap = BitmapFactory.decodeFile(item);
bitmap = ResizeImage.getResizedBitmap(bitmap, 100, 100);
Bitmap bitmap2 = ImageCornerMoulder.getRoundedCornerBitmap(bitmap, calculatePercentage(5, bitmap.getHeight()));
//add images we still have enough space
rootViewController = (rootViewController + 1);
View rootView = LayoutInflater.from(context).inflate(R.layout.expandable_image_item, null);
ImageView imageView = (ImageView) rootView.findViewById(R.id.clothItem);
rootView.setTag(new ImageObject(Uri.parse(item)));
imageView.setImageBitmap(bitmap2);
if(bitmap != bitmap2)
{
bitmap.recycle();
}
childViewHolder.linearLayout.addView(rootView, 0);
}
}
} catch (Exception e) {
e.printStackTrace();
//set default image
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.clothes);
bitmap = ResizeImage.getResizedBitmap(bitmap, 100, 100);
Bitmap bitmap2 = ImageCornerMoulder.getRoundedCornerBitmap(bitmap, calculatePercentage(5, bitmap.getHeight()));
//add images we still have enough space
rootViewController = (rootViewController + 1);
View rootView = LayoutInflater.from(context).inflate(R.layout.expandable_image_item, null);
ImageView imageView = (ImageView) rootView.findViewById(R.id.clothItem);
imageView.setImageBitmap(bitmap);
if(bitmap != bitmap) {
bitmap.recycle();
}
childViewHolder.linearLayout.addView(rootView, 0);
}
}
}
childViewHolder.linearLayout.invalidate();
}
private int calculatePercentage(int percentage, int target)
{
int k = (int)(target*(percentage/100.0f));
return k;
}
}
我是怎么用的
adapter = new ExpandableCategoryAdapter(addItems,goTo,getBaseContext(), data arraylist);
recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
recyclerView.setAdapter(adapter);
关于Android Recyclerview 向下滚动时滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32507719/
我在另一个 RecyclerView(parentRecyclerView) 中实现了 RecyclerView(childRecyclerView),图片说明了所有的实现: 我想编写一个 espre
我正在构建一个应用程序,它使用ViewPager2在页面之间水平滚动,每个页面都有一个垂直滚动的内容RecyclerView,其中每个列表的第一个位置都有一行水平滚动小部件,例如附加到寻呼机指示器类型
我正在尝试实现一个水平的 recyclerview 并且 recyclerview 的每个项目都将是一个具有网格布局的垂直 recyclerview。我面临的问题是,当我尝试垂直滚动子 recycle
我使用显示条目列表的 RecyclerView。每个条目都托管另一个 RecyclerView,它是一个图像列表。 我现在想让这个嵌套的 RecyclerView 可点击,而不是它的项目,而是整个 V
我正在尝试将手机中的图像加载到我的回收 View 中。 到目前为止,我已经创建了一个 recyclerview.adapter 和一个 gridlayoutmanager,并将它们附加到我的 recy
我需要一个可扩展 View ,其中父/可扩展标题将具有文本和下拉箭头。每个此类标题的子项应该是在网格结构中具有多个项目的 View 。 (有点像带有 GridLayoutManager 的回收器 Vi
我正在使用显示不同类别列表的 RecyclerView。每行项目还包含 RecyclerView 以显示类别项目列表。父级 RecyclerView 由垂直 LinearLayoutManager 填
我正在更新一个旧的 Android 项目,现在我从 RecyclerView 中反复收到这条日志语句: W/RecyclerView:RecyclerView 不支持滚动到绝对位置。改为使用 scro
在我的 Adapter 中,我调用 LayoutManager.ChildAt(position) 来获取 itemview,但是我得到的 View 不是匹配的 itemview,当我调用 notif
我正在从 ListView 迁移到 RecyclerView,但是在 SQLite 中输入一些数据后,我的列表没有使用 notifyDataSetChanged() 更新;所以我总是要调用setAda
我正在用 Google Now Cards 的风格创建一组 5 张卡片。我首先关注的是总体布局。 我正在使用 CardView 和 RecyclerView ,我想要实现的是这样的: 这是我的 Car
在我的应用程序中,我有一个 RecyclerView,其中包含一个简单的项目 View ,每行包含一个 TextView 和一个 Spinner。 用户从操作栏中单击“保存”后,我需要遍历所有项目并获
我正在尝试检查 RecyclerView 中是否可以看到某些特定项目;但我无法实现。请帮助我确定我的项目是否在 RecyclerView 中完全可见。 mrecylerView.addOnScroll
我有一个提要片段,它的主要元素是帖子的 RecyclerView。 我正在使用 Lisa Wray 的 Groupie 库管理回收站 https://github.com/lisawray/group
我有这两个类似的行为回收器 View 适配器,它们之间的唯一区别是 onclick 方法和传递给它们的对象。所以,我正在考虑将类 B 设计为从回收器 View 适配器继承,这样我就可以更改构造函数来执
这很奇怪。我对这个问题感到沮丧。我将数据保存在 ArrayList 中。当我将数据放在 RecyclerView 上时。数据未显示在列表中。这是我的代码 listOrder.forEach { ord
编辑我通过使用 CoordinatorLayout 和 AppBarLayout 作为 header 和 TabLayout 的包装解决了这个问题。本来应该很明显,但是哦,好吧。 原始问题:我有一个设
我有一个回收 View 。我想从其适配器类更新回收器 View 。我尝试了 notiftDataSetChanged( ) 但它只适用于主类。下面是 recyclerview 适配器类的代码。 pac
我正在使用具有不同 viewholders 的 recyclerview(具有垂直 LinearLayout),其中一个有另一个 RecyclerView(带有水平 LL)。在第二个 recycler
我想创建一个与 Google Play Store 或 Netflix App 类似的布局,其中在单个 RecyclerView 中基本上有多个水平 RecyclerView。如果这不是他们做事的方式
我是一名优秀的程序员,十分优秀!