我正在使用样式为@android:style/Widget.DeviceDefault.Light.ProgressBar.Small
的线性布局中的默认ProgressBar小部件(用于不确定的进度)>
如果我使用ProgressBar VISIBLE启动活动,并且从不将其设置为INVISIBLE或GONE,则显示为OK。但是,如果我在代码中的任意位置放置progressBar.setVisibility(progressBar.GONE);
或progressBar.setVisibility(progressBar.INVISIBLE);
,则ProgressBar的空间位于UI上,但看不到它。
我以为这可能是泄漏的并行线程,并从我的应用程序中删除了所有多线程,但是如果INVISIBLE
或GONE在我的代码中的任何位置,它仍然不会出现。在其他活动上也可以正常工作。
布局XML:
<?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:layout_editor_absoluteX="16dp" tools:layout_editor_absoluteY="260dp"> <ScrollView android:id="@+id/myTeamsScrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" tools:layout_editor_absoluteY="8dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/content_frame" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="left" android:orientation="horizontal"> <LinearLayout android:layout_width="32dp" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_marginLeft="16dp" android:orientation="vertical" android:paddingTop="32dp"> <ImageView android:id="@+id/menu1ImageView" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center" android:contentDescription="@string/userNavigationMenuButtonContent" android:onClick="openDrawer" app:srcCompat="@drawable/menu_icon" /> </LinearLayout> </LinearLayout> <EditText android:id="@+id/enterNewTeamEditText" android:layout_width="340dp" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_gravity="center_horizontal" android:contentDescription="@string/enterTeamNameEditTextcontent" android:ems="10" android:hint="@string/teamNameHint" android:inputType="textEmailAddress" android:textColor="@color/colorPrimary" /> <ProgressBar android:id="@+id/myTeamsProgressBar" style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Small" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="16dp" android:alpha="1" android:foregroundTint="#FFFFCC" android:progressTint="#FFFFCC" android:visibility="visible" /> <TextView android:id="@+id/deckTypeTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="16dp" android:contentDescription="@string/remotePokerlabelcontent" android:enabled="false" android:text="@string/newTeamDeckType" android:textAlignment="center" android:textColor="@color/colorPrimary" android:textSize="14sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/remotePokerTextView" /> <Spinner android:id="@+id/newTeamDeckTypeSpinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="8dp" android:background="@drawable/spinner" android:textAlignment="center" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/enterNewTeamEditText" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" android:paddingTop="16dp"> <Button android:id="@+id/createTeamButton" android:layout_width="wrap_content" android:layout_height="32dp" android:layout_gravity="center_horizontal" android:layout_marginEnd="8dp" android:layout_weight="1" android:background="@color/colorButton" android:contentDescription="@string/createTeamButtoncontent" android:fontFamily="@string/fontfamily" android:onClick="createTeam" android:text="Create Team" android:textColor="@color/colorPrimaryDark" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" android:paddingTop="16dp"> <Button android:id="@+id/receivedJoinRequestsButton" android:layout_width="147dp" android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:background="@color/colorButton" android:contentDescription="@string/createTeamButtoncontent" android:fontFamily="@string/fontfamily" android:onClick="showJoinRequests" android:text="@string/myTeamsJoinRequestsButton" android:textColor="@color/colorPrimaryDark" android:textSize="14sp" android:layout_weight="1" /> <Switch android:id="@+id/teamTypesSwitch" android:layout_width="143dp" android:layout_height="wrap_content" android:checked="false" android:fontFamily="@string/fontfamily" android:text="@string/switchMemberTeams" android:textColor="@color/colorPrimary" android:layout_weight="1" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:layout_marginTop="16dp" android:orientation="vertical"> <ListView android:id="@+id/myTeamsListView" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_marginBottom="32dp" android:layout_weight="1" android:alwaysDrawnWithCache="true" android:background="@drawable/spinner" android:contentDescription="@string/myTeamsListViewcontent" android:isScrollContainer="true" android:scrollbars="vertical" android:scrollingCache="true" android:smoothScrollbar="true"></ListView> </LinearLayout> </LinearLayout> </ScrollView> <com.google.android.material.navigation.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" android:onClick="onSwitchChange" app:headerLayout= "@layout/nav_header_main" app:menu="@xml/drawer_view" /> </androidx.drawerlayout.widget.DrawerLayout>
在Activity onCreate中,我打电话给
populateMemberTeams();
,我添加了一个CountDownTimer来检查progressBar是否在屏幕上,并且它是... 在2秒钟之前,有一个空白空间,但是我看不到ProgressBar
当计时器到期时,当ProgressBar更改为GONE时,UI会进行调整。
private void populateMemberTeams() { ListView myTeamsListView = findViewById(R.id.myTeamsListView); ProgressBar progressBar = findViewById(R.id.myTeamsProgressBar); progressBar.setVisibility(progressBar.VISIBLE); mAuth = FirebaseAuth.getInstance(); String userId = mAuth.getCurrentUser().getUid(); callTeamManagement.populateMemberTeams(TAG, passedActivity, context, userId); new CountDownTimer(2000, 1000) { public void onFinish() { progressBar.setVisibility(progressBar.GONE); } public void onTick(long millisUntilFinished) { // millisUntilFinished The amount of time until finished. } }.start(); }
我尝试过:
如果是颜色问题,请更改ProgressBar style
;INVISIBLE
将ProgressBar放入其自己的LinearLayout中
progressBar.setVisibility(progressBar.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(ProgressBar.VISIBLE);
我正在使用具有样式的线性布局中的默认ProgressBar小部件,以获取不确定的进度:@android:style / Widget.DeviceDefault.Light.ProgressBar.Small如果我从......开始活动,
您应使用runOnUiThread
。