我已经厌倦了查看寻呼机的代码,但它对我不起作用,因为我想像播放商店一样显示
HashMap<String, String> url_maps = new HashMap<String, String>();
url_maps.put("PragYal Gold", "http://sponsorimage/9434654.jpg");
url_maps.put("", "http://sponsorimage/4322132.jpg");
url_maps.put("Zee Bangles", "http://sponsorimage/2312958.png");
url_maps.put("", "http://sponsorimage/5134998.png");
url_maps.put("Mahapragya", "http://sponsorimage/6830009.png");
url_maps.put("", "http://sponsorimage/8537751.png");
url_maps.put("Zee Bangles", "http://sponsorimage/3549573.png");
url_maps.put("Shah & Comapny", "http://sponsorimage/5400190.png");
url_maps.put("", "http://sponsorimage/8135090.png");
for (String name : url_maps.keySet()) {
TextSliderView textSliderView = new TextSliderView(getApplicationContext());
// initialize a SliderLayout
textSliderView
.description(name)
.image(url_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);
//add your extra information
textSliderView.bundle(new Bundle());
textSliderView.getBundle()
.putString("extra", name);
mDemoSlider.addSlider(textSliderView);
}
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
mDemoSlider.setDuration(4000);
mDemoSlider.addOnPageChangeListener(this);
谢谢
答案 0 :(得分:1)
您必须在水平回收视图中将卡片视图用作行。
对于此行为,您必须将snaphelper与recyclerview一起使用。
Snaphelper是关键。无需使用任何库。
http://www.devexchanges.info/2016/09/android-tip-recyclerview-snapping-with.html?m=1
答案 1 :(得分:1)
请查看 VIEW PAGER 库:
答案 2 :(得分:0)
对于旧的ViewPager
,您可以像这样轻松完成:
viewPager.setClipToPadding(false);
viewPager.setPadding(48, 0, 48, 0);
viewPager.setPageMargin(24);
对于ViewPagger2
,请执行以下操作:
在xml中:
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="@dimen/_120sdp" />
在科特林:
viewPager2.adapter=SliderAdapter()
val rvInstance=viewPager2.children.first { it is RecyclerView } as RecyclerView
rvInstance.also {
it.setPadding(32.toPx(), 0, 16.toPx(), 0)
it.clipToPadding = false
it.addItemDecoration(ItemDecoration())
}
您的ItemDecoration类:
class ItemDecoration: RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
outRect.right = 16.toPx()
// outRect.left=16.toPx()
}
}
fun Int.toPx(): Int {
val metrics = Resources.getSystem().displayMetrics
val px = this * (metrics.densityDpi / 160f)
return Math.round(px)
}