android - 让 setVisibility 在片段中工作
问题描述
我无法让 ProgressBar 变得不可见。我根据其他 StackOverFlow Q&As 尝试了以下方法,但没有成功:
- 添加 clearAnimation() 方法
- 使用活动中的 getter 方法调用进度条
- 使用片段中的 getter 方法调用进度条
- 检查 findViewByID 是否返回 null(它没有)
- 完全在活动而不是片段中运行该方法
- 在 XML 中上下移动进度条
- 用处理程序调用它
提前非常感谢您的帮助。花了整整 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>
解决方案
推荐阅读
- postgresql - Postgres选择下一个时间戳非常慢
- c# - 如何将图像沿两条边缘合并到背景中?
- pyspark - 方法 col([class java.util.ArrayList]) 不存在
- c# - DataGridView 中单元格的鼠标左键和右键单击事件
- python - 关键字匹配和关键字计数
- excel - 如何通过 URL 链接到 Excel 单元格
- android - Android Firebase 自动断开与服务器的连接
- ios - 节拍器。定时器、音乐和动画
- reactjs - 与 TypeScript 反应 - 类型 {...} 不可分配给类型“只读
” - javascript - Javascript:IE 的等效解构赋值