I want a ProgressBar that is touching a bottom border of screen but with this piece of code, I am getting an little space between bar and screen border:
Here is a hack that could work:
That is what I can think of unless you want to create a custom style for the progressbar as mentioned in a comment above
I found a work around.I am basically adding a layout_marginBottom="-4dp" to my ProgressBar and wrapped it inside a RelativeLayout and aligned it to the bottom of the parent view.This changes may break your app in the future.For a better solution design a custom progress bar with your own custom drawable which you can align correctly and occupies less canvas space compared to the progressBarStyleHorizontal.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/imageButton”
android:layout_width="40dip"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:contentDescription="@string/descrp"
android:scaleType="center"
android:src="@drawable/some_drawable”
android:visibility="visible" />
<TextView
android:id="@+id/textview”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#FFFFFF"
android:textStyle="bold" />
//changes
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/some_other_id"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-4dp" />
</RelativeLayout></RelativeLayout>
Here's the link
I have been struggling with this for a while now. My conclusion: There is no way to archieve this behaviour with XML for arbitrary screen sizes. On some screen sesolutions the progress bar will always be misplaced a little.
My simple solution: Set the Y of the progressbar programmatically to the Y of the super view/layout
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
progressBar.setY(layout.getY() - progressBar.getHeight() / 2);
}
Works like a charm and for all screen sizes.
I came up with the solution to use a custom progressDrawable
without any paddings like this:
progress_bar_progress.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/accent"/>
</shape>
</clip>
</item>
And then reference it in your ProgressBar
:
<ProgressBar
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:background="#1A000000"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="false"
android:progressDrawable="@drawable/progress_bar_progress" />
Make your parent layout height as fill_parent and set progressbar height as match_parent.