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

标签 java android xml

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

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/

相关文章:

java - 将 JUNG 图写入图像 : can't reliably render complete graph

java - 带 EditText 的进度条

Android Studio 布局预览低分辨率

xml - LINQPad 抛出 System.OutOfMemoryException

java - Jaxb 如何为其他 xml 元素创建 xml 元素容器

xml - WCF XML 和列表序列化

java - Tomcat 服务器启动失败

java - PMD 内存泄漏

java - 打印 y 槽中 x 对象的所有组合 (Java)

java - 如何使用多线程通过FTP下载文件?