gpt4 book ai didi

java - Android FrameLayout 中的 ProgressBar 永远不可见

转载 作者:行者123 更新时间:2023-12-01 18:03:27 25 4
gpt4 key购买 nike

您好,我正在尝试在用户单击登录按钮时显示圆形进度条,类似于下面的屏幕截图。

enter image description here

问题是进度条永远不会显示,即使我在 LogInActivity.showProgressBar() 中将其可见性更改为 View.VISIBLE

progressBar.setVisibility(View.VISIBLE);.

activity_log_in.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout style="@style/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.LogInActivity">

<!-- TW Login Form -->
<include
android:id="@+id/log_in_form"
layout="@layout/log_in"/>

<!-- Loading Indicator -->
<ProgressBar
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>

</FrameLayout>

styles.xml

<resources>

<!-- ... -->

<style name="layout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@android:color/white</item>
</style>

<!-- ... -->

</resources>

LogInActivity.java

package com.trainerworkout.trainerworkout.activity;

// import ...

/**
* As a personal trainer I need to log in so that I can have access to the app.
*/
public class LogInActivity extends AppCompatActivity {
// variable declarations ...

// butterknife allows to eliminate findViewById calls by using @Bind on fields.
...
@Bind(R.id.progress_bar)
ProgressBar progressBar;
@Bind(R.id.log_in_form)
RelativeLayout logInForm;

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
context = this;
network = new Network(this);
ButterKnife.bind(this);

applyFont();

// Sets two colors for the TextView with HTML Formatting
//noinspection deprecation
not_a_member_text_view.setText(Html.fromHtml(getString(R.string.not_a_member_string)));

if (network.userIsLoggedIn()) {
logInRefresh();
} else {
showForm();
} // else
} // onCreate()

public void logInRefresh() {
showProgressBar();
network.logInRefresh(this);
showForm();
} // logInRefresh()

// ...

public void logInButtonClick(View view) {
Log.d(TAG, "logInButtonClick()");
// Prevent multiple clicks during the network call
logInButton.setEnabled(false);
if (network.userIsLoggedIn()) {
logInRefresh();
} else {
logIn();
} // else
logInButton.setEnabled(true);
} // logInButtonClick()

/**
* Prepares the log in request to the API
*/
private void logIn() {
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();

if (Valid.validFields(this, email, password, emailEditText, passwordEditText)) {
showProgressBar();
network.logIn(this, email, password);
showForm();
} else {
shakeLogInButton();
} // else
} // logIn()

// ...

public void showForm() {
progressBar.setVisibility(View.GONE);
logInForm.setVisibility(View.VISIBLE);
} // showProgressBar()

public void showProgressBar() {
progressBar.setVisibility(View.VISIBLE);
logInForm.setVisibility(View.GONE);
} // showProgressBar()
} // LogInActivity

编辑 - log_in.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- TW Log In Form -->
<RelativeLayout
style="@style/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.LogInActivity">

<LinearLayout
style="@style/layout"
android:layout_margin="@dimen/layout_margin_profile"
android:gravity="center"
android:orientation="vertical">

<!-- ... -->

<!-- Email Field -->
<EditText
android:id="@+id/email_edit_text"
style="@style/edit_text"
android:layout_height="wrap_content"
android:hint="@string/email"
android:inputType="textEmailAddress"/>

<-- ... -->


</RelativeLayout>

最佳答案

android:translationZ="8dp" 添加到进度条

关于java - Android FrameLayout 中的 ProgressBar 永远不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38831285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com