当进度条可见时隐藏片段的内容

时间:2020-06-30 05:35:57

标签: android android-layout android-fragments android-progressbar

我的片段包含许多不同的视图。某些视图已经存在于XML文件中,例如imageview,可绘制对象等,而其他视图在Retrofit成功响应后被数据填充。 XML文件还包含一个工具栏和progressbar

当数据来自服务器时,我只希望显示工具栏和进度栏,而其他内容则隐藏。但是问题是我无法隐藏整个视图,因为它本身包含一个工具栏和进度条。

我该怎么办?

Output I want Output I am getting

<RelativeLayout 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...>

 <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swiperefresh_open_post"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_sec">

 <!-- this contains all Content I want to hide this -->
    <ScrollView...>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


 <!-- this contains content which is fixed at the bottom I also want to hide this -->
<FrameLayout...>

<include layout="@layout/progressbar_item" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

只需将视图放到其他地方即可。例如,如果使用FrameLayout,则可以具有相当平坦的结构,其中ToolbarProgressBar与内部FrameLayout处于同一层次结构级别,内部<FrameLayout android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent"> <Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="56dp" /> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="56dp" > <!-- Put your layout here --> </FrameLayout> <ProgressBar android:id="@+id/progressbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" /> </FrameLayout> 包含其余布局。因此,您可以执行以下操作:

container.visibility = View.GONE
progressbar.visibility = View.VISIBLE

然后打电话给

container.visibility = View.VISIBLE
progressbar.visibility = View.GONE

    div {
        display: flex;
        padding: 10px;
        align-items: center;
    }
    span {
        height: 40px;
        width: 5px;
        background-color: #FECC01;
        border-radius: 99px;
        margin: 0 20px;
    }
相关问题