2016-08-08 15 views
0

Hallo Ich versuche, eine kreisförmige Fortschrittsbalken zu zeigen, wenn der Benutzer auf die Anmeldeschaltfläche klickt, ähnlich wie im Screenshot unten.Android ProgressBar in FrameLayout ist nie sichtbar

enter image description here

Problem ist der Fortschrittsbalken wird nie i gezeigt, auch hart verändert es die Sichtbarkeit zu View.VISIBLE in LogInActivity.showProgressBar() mit

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 

EDIT - 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> 
+0

progressBar.setMax (150); in showProgressBar() –

Antwort

1

Hier Ausgabe mit

<include 
    android:id="@+id/log_in_form" 
    layout="@layout/log_in"/> 

einmal überprüfen es Eigentum ist.

Wenn möglich, dann Code-Snippet senden.

enter image description here

+0

Ich habe mit Ihrem Code getestet und funktioniert gut außer ViramP

+0

Ich habe das Code-Snippet am Ende in meiner Bearbeitung hinzugefügt. Bitte guck dir das an. – charlesfranciscodev

+0

Ich habe mit Ihrem Code überprüft und funktioniert immer noch gut – ViramP

1

hinzufügen android:translationZ="8dp" zu Ihrem progressbar

+1

Dies ist ein guter Kommentar, aber keine Antwort – manetsus