Hankkin / PageLayoutDemo

🥭一款简单的page切换 空布局、错误布局、加载布局,支持一键配置、定义,不需要xml编写
248 stars 30 forks source link

麻烦看一下这个问题 #6

Open eicky opened 5 years ago

eicky commented 5 years ago
<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#25cad5"
        android:paddingLeft="13dp"
        android:paddingTop="7dp"
        android:paddingRight="13dp"
        android:paddingBottom="7dp"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="34dp"
            android:background="@drawable/search_bg"
            android:gravity="left|center_vertical"
            android:paddingLeft="34dp"
            android:text="搜索小组" />
    </androidx.appcompat.widget.Toolbar>

    <com.scwang.smart.refresh.layout.SmartRefreshLayout
        android:id="@+id/refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tool_bar">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </com.scwang.smart.refresh.layout.SmartRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

如果我的fragment是这个布局,然后我调用的initPage(refresh_layout),后面hide之后,我的recyclerview就显示不出来了

eicky commented 5 years ago

我找到问题了,是根布局的问题,如果把ConstraintLayout换成LinerLayout或者RelativeLayout就没问题,但是如果要使用ConstraintLayout怎么解决呢?

Hankkin commented 5 years ago

OK 等我抽空看下哈 更新后会及时回复你的

Hankkin commented 5 years ago

你好大概看了一下,约束性布局作为跟布局暂时不支持,因为整体的原理可以看下PageLayout中initPage()方法;是将你传入的布局先移除掉,然后加入到PageLayout中,再把PageLayout放入跟布局中,目前猜测如果跟布局是ConstraintLayout的话,移除后约束性关系就没有了,需要手动再去设置原约束,试了一下没成功,后续考虑优化上去,暂时先用普通布局吧。抱歉

eicky commented 5 years ago

你好大概看了一下,约束性布局作为跟布局暂时不支持,因为整体的原理可以看下PageLayout中initPage()方法;是将你传入的布局先移除掉,然后加入到PageLayout中,再把PageLayout放入跟布局中,目前猜测如果跟布局是ConstraintLayout的话,移除后约束性关系就没有了,需要手动再去设置原约束,试了一下没成功,后续考虑优化上去,暂时先用普通布局吧。抱歉

谢谢大佬,这个应该就是把原来的约束的清除掉了

YuPf1989 commented 5 years ago

我发现了另外的一个库,思路和你是一样的,它里边有对ConstraintLayout布局的处理,可以作为参考: https://github.com/luckybilly/Gloading

Hankkin commented 5 years ago

好的多谢