最近遇到了一个我要解决的问题,但是我找不到解决方案。
在我的项目中,我得到了一个片段,该片段使布局夸大,其中包含一个viewPager
。到这里为止一切正常,但是当我运行该项目以在智能手机上查看该项目时,除了viewpager
以外,所有内容都会显示出来。我是否有需要重新考虑的地方?这是我在viewpager
方法的各个片段上得到的onCreateView
的结果:
viewPager = conteudo_feridas.findViewById<View>(R.id.viewPagerGaleria) as ViewPager
val adapter = ViewPageAdapter(activity!!.application)
viewPager.adapter = adapter
viewPager.currentItem = images.size
在我的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 numeroFotos.size
return dias.size
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 nrFotos = v.findViewById<View>(R.id.dados_galeria_nr_fotos) as TextView
val dados = v.findViewById<View>(R.id.dados_galeria_data) as TextView
val image = v.findViewById<View>(R.id.image_view) as ImageView
vp.addView(v, 0)
return v
Viewpager的布局也是如此:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewPagerGaleria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/pageIndicatorView">
</android.support.v4.view.ViewPager>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
app:layout_constraintBottom_toTopOf="@id/viewPagerGaleria"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:piv_padding="50dp"
app:piv_animationType="scale"
app:piv_viewPager="@id/viewPagerGaleria"
android:layout_height="wrap_content"
/>