airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.52k stars 726 forks source link

how to add strip to the row? #1170

Open muklasr opened 3 years ago

muklasr commented 3 years ago

I've tried to create it, but it messy when i update the data and refresh the recyclerview.

rohithThammaiah commented 3 years ago

Do you mean a divider using epoxy? If so create an EpoxyModel<*> with your custom divider and add it after your view.

Example:

<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/layout_divider_view"
  android:layout_width="match_parent"
  android:layout_height="4dp"
  android:background="#eeeeee" />

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class ItemDivider @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
  init {
    View.inflate(context, R.layout.layout_epoxy_divider, this)
  }
}

And finally, you can add it to your controller

yourRecyclerView.withModels {
    yourList.forEach {
        YourView_()
                .id("View")
                .addTo(this)

        ItemDividerModel_()
                .id("Divider")
                .add(this)
    }
}
muklasr commented 3 years ago

Thank you for your response. But, that's not what I mean, I mean how to make different background color for item between odd index and even index. Like this [http://1.bp.blogspot.com/-BiWZv4ZvQPU/VgmJCPNlybI/AAAAAAAAAOQ/rVIYkh_ilNs/s1600/Screenshot_2015-09-28-22-25-35.png]