首页 > 解决方案 > 让 setVisibility 在片段中工作

问题描述

我无法让 ProgressBar 变得不可见。我根据其他 StackOverFlow Q&As 尝试了以下方法,但没有成功:

提前非常感谢您的帮助。花了整整 2 天的时间在这件事上

分段:

public class SwipeFragment extends Fragment {


public ProgressBar mProgressBar;


@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle onStavedInstanceState) {

    View rootView = inflater.inflate(R.layout.swipe_activity_main, container, false);

    mProgressBar = rootView.findViewById(R.id.progress_bar_load_candidates);
    mProgressBar.clearAnimation();
    mProgressBar.setVisibility(View.INVISIBLE);

    return rootView;
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview_candidates"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/view_main_bottom_nav"
        android:layout_height="0dp"
        android:layout_width="0dp" />

    <ProgressBar
        android:id="@+id/progress_bar_load_candidates"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateTint="@color/colorKLMBlue"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/drop_shadow_elevation"
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="@drawable/drop_shadow_elevation_upwards"
        android:elevation="4dp"
        app:layout_constraintBottom_toTopOf="@id/view_main_bottom_nav" />

    <com.xx.android.xxx.ui.bottomnav.BottomNavBar
        android:id="@+id/view_main_bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:elevation="4dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <FrameLayout
        android:id="@+id/layout_main_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toTopOf="@+id/view_main_bottom_nav"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" >
    </FrameLayout>

</android.support.constraint.ConstraintLayout>

标签: androidandroid-fragmentsprogress-barvisibility

解决方案


推荐阅读