Kotlin-普通片段内的常规Viewpager(图片库)不显示

时间:2018-11-19 11:49:57

标签: android kotlin android-viewpager fragment show

很简单,我有一个'localNotification' was deprecated in iOS 10.0: Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:] ,其中的某些图像包含在viewpager布局中。当我运行项目时,所有的布局都会显示出来,但是fragment却不会……就像这样:

enter image description here

因此,我将重要的代码放在这里。首先,viewpager

Viewpager

各自的片段:

class ViewPageAdapter(private val context: Context) : PagerAdapter(){
    private var layoutInflater:LayoutInflater?= null

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }

    override fun getCount(): Int {
        return images.size
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        /**Set our vals to "inflate"**/
        layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val v = layoutInflater!!.inflate(R.layout.custom_layout, null)
        val image = v.findViewById<View>(R.id.image_view) as ImageView

        /**Positions of images**/ 
        auxPosition = images[position]

        val vp = container as ViewPager

        /** Add custom_layout.xml to our viewpager**/
        vp.addView(v, 0)

        return v
    }
}

viewpager的布局:

class FeridasFragment : Fragment() {

internal lateinit var viewPager: ViewPager

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {

    val conteudo_feridas=inflater!!.inflate(R.layout.fragment_feridas, container, false)

    //the viewpager
    viewPager = conteudo_feridas.findViewById<View>(R.id.viewPagerGaleria) as ViewPager
    val adapter = ViewPageAdapter(activity!!.application)
    viewPager.adapter = adapter
    viewPager.currentItem = images.size

    //nav dots of viewpager
    val pageIndicatorView = conteudo_feridas.findViewById<View>(R.id.pageIndicatorView) as PageIndicatorView
    pageIndicatorView.setViewPager(viewPagerGaleria)
    pageIndicatorView.count = images.size
    pageIndicatorView.selection = images.size

    return conteudo_feridas
}

0 个答案:

没有答案