PageIndicatorView
PageIndicatorView copied to clipboard
Can't display in Kotlin Porject
when I set the viewPager and the count is 5,but theindicator not show;
this is value:
I think we will need to see your layout xml files to be able to see what is going on. It looks like the PageIndicatorView
is working correctly but not being displayed from what you've shown
this is my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="230dp"
android:background="@android:color/white"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.15"
android:background="#000000"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:padding="10dp"
android:text=""
android:textColor="@android:color/white"
android:textSize="20dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:piv_animationType="drop"
app:piv_padding="5dp"
app:piv_radius="4dp"
/>
</LinearLayout>
</RelativeLayout>
and this is the viewPagerAdapter code
class TopStoryAdapter(var context: Context,
var viewList: ArrayList<View>,
var transformer: LifecycleTransformer<Any>,
var topStories: ArrayList<TopStoryEntity>) : PagerAdapter() {
var itemClickListener: AdapterItemClickListener? = null
override fun instantiateItem(collection: ViewGroup, position: Int): Any {
val view = viewList[position]
var image: ImageView = view.findViewById(R.id.image) as ImageView
ImageLoader.loadImage(context,
topStories[position].image,
R.mipmap.image_small_default,
image!!)
ViewUtils.viewClick(image, transformer,
Consumer<Any> {
itemClickListener?.itemClickListener(position)
})
collection.addView(view)
return view
}
override fun destroyItem(collection: ViewGroup, position: Int, view: Any) {
collection.removeView(view as View)
}
override fun getCount(): Int {
return viewList.size
}
override fun isViewFromObject(view: View, `object`: Any): Boolean {
return view === `object`
}
override fun getItemPosition(`object`: Any?): Int {
return PagerAdapter.POSITION_NONE
}
}
I use this layout as a headItem in recyclerView; and the source code is here
I'm not sure if this can help you, but I set the viewPager by the XML and its working over here... Also, in Kotlin you can avoid to call find(YourViewID). Check it here: https://stackoverflow.com/a/34448660/7806488