我正在使用样式为-[[CADisplayLink]invalidate]
如果我使用ProgressBar VISIBLE开始活动,但从未将其设置为INVISIBLE或GONE,则显示正常。但是,如果我将@android:style/Widget.DeviceDefault.Light.ProgressBar.Small
或progressBar.setVisibility(progressBar.GONE);
放在代码中的任何位置,则ProgressBar的空间位于UI上,但看不到它。
我认为这可能是泄漏的并行线程,并从我的应用程序中删除了所有多线程,但是如果不可见或 GONE 位于我的代码。
在其他活动上运行正常。
布局XML:
progressBar.setVisibility(progressBar.INVISIBLE);
在Activity onCreate中,我打电话给<?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>
,我添加了一个CountDownTimer来检查progressBar是否在屏幕上并且是否...... 在2秒钟之前,有一个空白空间,但是我可以没有看到ProgressBar
当计时器到期时,当ProgressBar更改为GONE时,UI会进行调整。
populateMemberTeams();
我尝试过:
如果是颜色问题,请更改ProgressBar 样式;
不可见,而不是消失;
将ProgressBar放入其自己的LinearLayout中
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.setVisibility(progressBar.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
答案 0 :(得分:0)
您应该使用runOnUiThread
。
用于在UI线程上运行方法的一部分的Helper方法。
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.VISIBLE);
//progressBar.setVisibility(View.INVISIBLE);
//progressBar.setVisibility(View.GONE);
}
});