पर अतिरिक्त पैडिंग जोड़ने वाले सजावटी देखें, इसलिए, मुझे अपनी परियोजना में रीसाइक्लर व्यू को लागू करते समय एक अजीब समस्या का सामना करना पड़ रहा है। मेरे पास एक स्थिर शीर्ष और नीचे पैडिंग को लागू करने के लिए एक कस्टम सजावट है और तत्वों के बीच पैडिंग का एक अलग मूल्य है। जब भी मैं रीफ्रेश पर टैप करता हूं, यानी बैक एंड से डेटा लाता है और रीसाइक्लर व्यू को फिर से प्रदर्शित करता है, तो पैडिंग बढ़ जाती है और यह प्रत्येक रीफ्रेश पर बढ़ती रहती है।पुनर्चक्रण देखें रीफ्रेश
जब मैं ताज़ा हिट अंतरिक्ष (के कारण AsyncTask फिर से निष्पादित करने के लिए), के बीच आइटम वृद्धि हुई है। और यह प्रत्येक ताज़ा करने के साथ बढ़ता रहता है।
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp"
>
<RelativeLayout
android:id="@+id/itemLinearTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="17dp"
android:paddingRight="10dp"
android:paddingLeft="10dp">
<TextView
android:id="@+id/tv1"
android:textColor="@color/logo_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tv1"
android:textColor="@color/logo_black"
android:layout_alignParentRight="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- More elements -->
</RelativeLayout>
</android.support.v7.widget.CardView>
मैं आरंभ कर रहा हूँ और इस तरह RecyclerView पॉप्युलेट:
मैं RecyclerView अंदर इस
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusableInTouchMode="false">
</android.support.v7.widget.RecyclerView>
से पॉप्युलेट सामग्री की तरह एक ठेठ RecyclerView निम्नलिखित लेआउट के साथ CardView है:
// In PostExecute of AsyncTask
RecyclerView rv = (RecyclerView) rootView.findViewById(R.id.recyclerview);
RecycleViewAdapter adapter = new FuelPricesRecycleViewAdapter(data);
rv.setAdapter(adapter);
rv.addItemDecoration(new RecyclerViewItemDecoration(30, item_count - 1));
और ये मेरे RecyclerViewItemDecoration वर्ग ऐसा दिखाई देता है:
public class RecyclerViewItemDecoration extends RecyclerView.ItemDecoration {
private int space = 0;
private int item_count = 0;
private int ADDITIONAL_PADDING = 20;
public RecyclerViewItemDecoration(int space, int item_count) {
this.space = space;
this.item_count = item_count;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if(parent.getChildPosition(view) != item_count)
outRect.bottom = space;
// Add top margin only for the first item to avoid double space between items
if(parent.getChildPosition(view) == 0)
outRect.top = space + ADDITIONAL_PADDING;
if(parent.getChildPosition(view) == item_count)
outRect.bottom = space + ADDITIONAL_PADDING;
}
}
आपकी मदद के लिए धन्यवाद!
कुछ भी मिला है तो इसे ठीक करें? – codevscolor
लगभग एक साल बाद, मुझे एक ही समस्या का सामना करना पड़ रहा है क्या आप रीफ्रेशर के बाद RecyclerView.scrollToPosition() को कॉल करते हैं? – Fraid
अरे, क्या आपको कोई समाधान मिला? वर्तमान में मैं 'adapter.notifyItemRangeChanged (0, adapter.getItemCount(), खाली सूची()) को कॉल कर रहा हूं; 'एक वर्कअराउंड के रूप में।यह दृश्यों को दोबारा बिना सभी वस्तुओं को अमान्य कर देगा क्योंकि एक पेलोड है। (पेलोड कोई गैर-शून्य वस्तु हो सकती है)। मैं अभी भी एक बेहतर तरीका खोजना चाहूंगा। –