美文网首页
2021-11-25 TextClock和ViewPager2的

2021-11-25 TextClock和ViewPager2的

作者: 精巧的中级星光 | 来源:发表于2021-11-25 09:56 被阅读0次

页面结构使用了ViewPager2套Fragment形式
其中一个fragment中用了TextClock控件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

    <TextClock
        android:id="@+id/textClock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:format24Hour="yyyy/MM/dd HH:mm:ss"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
QQ浏览器截图20211125095336.png

此时切换到其他页面,就会闪一下回到第一页

把TextClock去掉就会正常,后来发现增加

viewPager2.setOffscreenPageLimit(3);

就正常了,原因不知道..

相关文章

网友评论

      本文标题:2021-11-25 TextClock和ViewPager2的

      本文链接:https://www.haomeiwen.com/subject/nyjatrtx.html