Reputation: 655
I have below layout file. I need to show a Progressbar in the layout.Currently Progressbar is taking up blank space in the middle so it devided my top and bottom view while showing the bar but I am trying to show the progressbar as an overlay over the layout so it will not take up any space. How Can I achieve this
This is the layout file currently I have
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgLeftArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left_arrow2"></ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imgGreendot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_dot"></ImageView>
<TextView
android:id="@+id/tvStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></TextView>
</LinearLayout>
<ImageView
android:id="@+id/imgBid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></ImageView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/tvExpected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></TextView>
<TextView
android:id="@+id/tvTotalBid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Bids | "
android:textColor="#a9a9a9"
android:textSize="14dp"></TextView>
<TextView
android:id="@+id/tvDeclined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></TextView>
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar5"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible" />
<LinearLayout
android:id="@+id/layoutswitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:text="Show Active Drivers Only" />
</LinearLayout>
</LinearLayout>
Upvotes: 2
Views: 2669
Reputation: 754
Use constraint layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgLeftArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_vector_test" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imgGreendot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_vector_test" />
<TextView
android:id="@+id/tvStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="@+id/imgBid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/tvExpected"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvTotalBid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Bids | "
android:textColor="#a9a9a9"
android:textSize="14dp" />
<TextView
android:id="@+id/tvDeclined"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/layoutswitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:text="Show Active Drivers Only" />
</LinearLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar5"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:indeterminate="true"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/linearLayout3"
app:layout_constraintEnd_toEndOf="@+id/linearLayout3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/linearLayout3" />
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 2