为什么我的寻呼机适配器什么都不显示?

如何解决为什么我的寻呼机适配器什么都不显示?

我想构建一个寻呼机适配器。我创建了适配器并将其设置为视图寻呼机,但屏幕上没有任何显示。请帮我解决这个问题。 我的传呼机视图仍然是白色的... 这是代码

适配器类

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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?