[英]Android ProgressBar in FrameLayout is never visible
Hello I'm trying to show a circular progress bar when the user clicks on the log in button, similar to the screenshot below. 您好,我试图在用户单击“登录”按钮时显示一个圆形进度栏,类似于下面的屏幕截图。
Problem is the progress bar is never shown, even tough i changed it's visibility to View.VISIBLE in LogInActivity.showProgressBar()
with 问题是进度条永远不会显示,即使很难,我也更改了
LogInActivity.showProgressBar()
中LogInActivity.showProgressBar()
的可见性
progressBar.setVisibility(View.VISIBLE);
. 。
activity_log_in.xml 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 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 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
EDIT - log_in.xml 编辑-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"
到进度条
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.