滾動位置我有以下的佈局,是一個包含HorizontalScrollViewHorizontalScrollView如何節省刷新
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearlayout"
android:orientation="horizontal">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">
<me.test.myCustomView
android:id="@+id/myCustomView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
</LinearLayout>
每當我試着在一排,比打電話notifyItemChanged水平滾動垂直RecyclerView的行(INT位置)刷新我剛剛滾動的當前行,佈局完全刷新,並且HorizontalScrollView的滾動位置返回到0.
如何在保存x滾動位置時刷新recycleView的其中一行一旦onBindViewHolder被再次調用,我可以檢索滾動位置並設置我t到HorizontalScrollView?
編輯:爲什麼你叫notifyItemChanged
滾動到某個項目之後刷新當前行的適配器
public class MyAdapter extends RecyclerView.Adapter<MyAdapter .ViewHolder> {
List<Data> data=new ArrayList<>();
public MyAdapter(ArrayList<StepData> data) {
this.data=data;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v;
v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.testing, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.customView.setData(this.data.get(holder.getAdapterPosition()));
holder.customView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addItem(holder.getAdapterPosition());
}
});
}
@Override
public int getItemCount() {
return this.data.size();
}
public void addItem(int position) {
this.data.add(data.get(position).getExtraData())
notifyItemChanged(position);
notifyItemInserted(position+1);
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public MyCustomViewcustomView;
public ViewHolder(View v) {
super(v);
customView = (MyCustomView) v.findViewById(R.id.myCustomView);
}
}
}
郵政適配器 –
確定我添加的代碼 – user126789