Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to best place my obscured ProgressBar on a ConstraintLayout on the screen?

I have a progress bar that shows up when I click on the Login button. I made modifications to the layout by adding a Toolbar at the top and it seems this toolbar is now obscuring the progressbar.

How can I make this progress bar visible somewhere in the center of the screen?

Thank you very much for your help.

The layout xml code is as shown below:

activity_login.xml

<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:gravity="center"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_marginBottom="64dp"
    android:background="@android:color/white"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:layout_constraintBottom_toTopOf="@+id/edittext_username"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<EditText
    android:id="@+id/edittext_username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="24dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:drawablePadding="8dp"
    android:gravity="center_vertical"
    android:hint="@string/edittext_username"
    app:layout_constraintBottom_toTopOf="@+id/edittext_password"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="@+id/button_login" />

<EditText
    android:id="@+id/edittext_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="24dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:drawablePadding="8dp"
    android:gravity="center_vertical"
    android:hint="@string/edittext_password"
    android:inputType="textPassword"
    app:layout_constraintBottom_toTopOf="@+id/button_login"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent" />

<Button
    android:id="@+id/button_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:text="@string/button_login"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent" />

<ProgressBar
    android:id="@+id/progressbar_login_progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:visibility="gone" />

</android.support.constraint.ConstraintLayout>
like image 673
sage Avatar asked Feb 17 '18 16:02

sage


People also ask

How do I center my progress bar?

Just change your Layout as RelativeLayout and add android:layout_centerInParent="true" to your ProgressBar. Save this answer.

Which attribute is used to display ProgressBar horizontally?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.

Can we use RelativeLayout inside ConstraintLayout?

In addition, guidelines can be used to create percentage-based layouts. Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout. However, learning the basics of LinearLayout and RelativeLayout is important before trying to understand how to use it with ConstraintLayout.

How do I center an image in constraint layout in Android?

Just add android:gravity="center" in your layout and done :) Show activity on this post.


1 Answers

Use next code to center your ProgressBar

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:gravity="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
like image 80
user311086 Avatar answered Sep 28 '22 00:09

user311086