Ich habe eine recyclerview wie das Bild untenWie kann man den Recyclerview-Hintergrund (nicht den Item-Hintergrund) dynamisch ändern, basierend auf der Position des Kindes?
die Hintergrundfarbe dynamisch Adapter Position gegeben ist, also nur dann, wenn Artikel (Karte) ist i die Hintergrundfarbe kann ich als cardview der Eltern Linearlayout haben und ich färbt das lineare Layout ein.
recyclerview:
<android.support.v7.widget.RecyclerView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="40dp"
style="@style/scrollbar_style"
/>
dies Artikel Ressource:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/back"
android:paddingBottom="10dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iconEntry"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_marginBottom="2dp"/>
<TextView
android:id="@+id/titleEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:layout_marginBottom="2dp"/>
<TextView
android:id="@+id/titleSpanishEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:layout_marginBottom="2dp"/>
<TextView
android:id="@+id/countEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textSize="10sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Adapter:
public LinearLayout back;
public MyViewHolder(View view) {
super(view);
back = view.findViewById(R.id.back);
}
Adapter onBindViewHolder:
holder.back.setBackgroundColor(Color.parseColor(
EntriesItemList.get(getCategory(position))
.getDisposalTypeCategory()
.getColor()));
jetzt ist die Anforderung Farbe, auch wenn es keinen Gegenstand wie den leeren Raum im 1. Abschnitt gibt.
das kann nur getan werden, wenn ich den Recyclerview Hintergrund (nicht Kartenhintergrund) dynamisch basierend auf Adapterposition ändern kann, aber sieht unmöglich aus, da es keine Beziehung zwischen den beiden gibt. irgendwelche Vorschläge, wie man das macht?
Eher Farbe zum einzelnen recycler Sicht geben Hintergrundfarbe zu diesem spezifischen Recycler anzeigen –
das ist meine Frage .. wie man Farbe recyclerview programmatically auf Position dynamisch geben, kann es 1 einzelne Farbe nicht sein –
@SiddarthG wie haben Sie verschiedene Artikel in jedem Abschnitt laden? –