问题描述
我想构建一个寻呼机适配器。我创建了适配器并将其设置为视图寻呼机,但屏幕上没有任何显示。请帮我解决这个问题。 我的传呼机视图仍然是白色的... 这是代码:
适配器类
class WelcomeViewPagerAdapter(private val context: Context?,private val listofCards:ArrayList<String>) : PagerAdapter() {
override fun isViewFromObject(view: View,`object`: Any): Boolean {
return view === `object` as LinearLayout
}
override fun getCount(): Int {
return listofCards.size
}
override fun instantiateItem(container: ViewGroup,position: Int): Any {
val view = LayoutInflater.from(this.context).inflate(R.layout.welcome_view_pager_view,container,false)
view.titleTextView.text = listofCards[position]
view.descriptionTextView.text = listofCards[position]
container.addView(view)
return view
}
override fun destroyItem(container: ViewGroup,position: Int,`object`: Any) {
container.removeView(`object` as LinearLayout)
}
}
片段类
val listofMessages = ArrayList<String>()
listofMessages.add("Lorem ipsum dolor sit amet,consec")
listofMessages.add("Lorem ipsum dolor sit amet,consec")
welcomeViewPager.adapter = WelcomeViewPagerAdapter(context,listofMessages)
welcome_view_pager_view.xml xml中的代码
<LinearLayout
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:orientation="vertical"
android:background="#FFF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:textAlignment="center"
android:layout_height="wrap_content"
android:text="Welcome to Food Point"
android:textSize="26sp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:fontFamily="@font/open_sans_semibold"
android:textColor="#343434" />
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="match_parent"
android:paddingTop="15dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:text="Please give access your camera so that we can scan and provide you that what\n is inside the food"
android:textSize="15sp"
android:paddingStart="60dp"
android:paddingEnd="60dp"
android:paddingBottom="15dp"
android:fontFamily="@font/open_sans_semibold"
android:textColor="#343434" />
片段xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#f8f8f8"
tools:context=".screens.WelcomeFragment">
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/bicycle"
android:scaleType="fitCenter"
android:layout_gravity="center"
android:layout_marginTop="40dp"
app:riv_corner_radius="100dp"
app:riv_mutate_background="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Let's get started"
android:fontFamily="@font/open_sans_bold"
android:textColor="#343434"
android:textAlignment="center"
android:layout_marginTop="24dp"
android:textSize="24sp"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/welcomeViewPager"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_marginTop="44dp" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/welcomePagerDots"
android:layout_width="80dp"
android:layout_height="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/welcomeViewPager"
app:tabBackground="@drawable/view_pager_tab_selector"
app:tabGravity="center"
android:backgroundTint="#ffffff"
app:tabIndicatorHeight="0dp"
app:tabPaddingEnd="10dp"
app:tabPaddingStart="10dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:background="@drawable/rounded_bg_50"
android:backgroundTint="#3061D7"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:text="Create account"
android:fontFamily="@font/open_sans_light"
android:textColor="#fff"
android:textSize="17sp"
android:textAllCaps="false"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:background="@drawable/rounded_bg_50"
android:backgroundTint="#fff"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_marginTop="15dp"
android:text="Login"
android:fontFamily="@font/open_sans_light"
android:textColor="#343434"
android:textSize="17sp"
android:textAllCaps="false"/>
某些文本,某些文本,某些文本某些文本,某些文本,某些文本某些文本,某些文本,某些文本某些文本,某些文本,某些文本某些文本,某些文本,某些文本某些文本,某些文本,某些文本某些文本,某些
override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_welcome,false)
}
override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
super.onViewCreated(view,savedInstanceState)
val listofMessages = ArrayList<String>()
listofMessages.add("Lorem ipsum dolor sit amet,consec")
listofMessages.add("Lorem ipsum dolor sit amet,consec")
welcomeViewPager.adapter = WelcomeViewPagerAdapter(context,listofMessages)
welcomePagerDots.setupWithViewPager(welcomeViewPager)
welcomeViewPager.invalidate()
for (i in 0 until welcomePagerDots.tabCount) {
val tab = (welcomePagerDots.getChildAt(0) as ViewGroup).getChildAt(i)
(tab.layoutParams as ViewGroup.MarginLayoutParams).setMargins(0,30,0);
tab.requestLayout()
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)