Closed zhpanvip closed 4 years ago
BVP是可以支持使用DataBinding的,需要通过BindingAdapter:
@BindingAdapter(value = {"binding:adapter", "binding:indicator", "binding:pageClick"}, requireAll = false) public static void bindBanner(BannerViewPager<BannerBean, BannerViewHolder> banner, BannerAdapter adapter, BaseIndicatorView indicatorView, BannerViewPager.OnPageClickListener pageClickListener) { Resources resources = banner.getContext().getResources(); banner.setIndicatorSlideMode(IndicatorSlideMode.SCALE) .setIndicatorStyle(IndicatorStyle.ROUND_RECT) .setAdapter(adapter) .setAutoPlay(true) .setScrollDuration(700) .setIndicatorView(indicatorView) .setOnPageClickListener(pageClickListener) .setIndicatorSliderColor(resources.getColor(R.color.color_slider_normal), resources.getColor(R.color.colorPrimary)) .setPageStyle(PageStyle.MULTI_PAGE_SCALE) .setIndicatorSliderWidth( resources.getDimensionPixelOffset(R.dimen.dp_4), resources.getDimensionPixelOffset(R.dimen.dp_10)) .setIndicatorSliderGap(resources.getDimensionPixelOffset(R.dimen.dp_4)).create(); }
然后在布局文件中通过binding:adapter="@adapter"进行绑定Adapter:
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:binding="http://schemas.android.com/tools"> <data> <variable name="adapter" type="com.zhpan.oneandroid.adapter.BannerAdapter" /> <variable name="pageClick" type="com.zhpan.bannerview.BannerViewPager.OnPageClickListener" /> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <com.zhpan.bannerview.BannerViewPager android:id="@+id/banner_view" android:layout_width="match_parent" android:layout_height="@dimen/dp_220" binding:adapter="@{adapter}" binding:indicator="@{indicator}" binding:pageClick="@{pageClick}" /> </RelativeLayout> </layout>
详细使用可以参考这里
BVP是可以支持使用DataBinding的,需要通过BindingAdapter:
然后在布局文件中通过binding:adapter="@adapter"进行绑定Adapter:
详细使用可以参考这里