Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressBar height=match_parent

I have an RelativeLayout with a radiobutton and a progressbar. The radiobutton should define the height of the RelativeLayout so the ProgressBar should have the same height as the radiobutton. But it hasn't.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:progressDrawable="@drawable/progress" />

    <RadioButton
        android:id="@+id/radioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
like image 911
wutzebaer Avatar asked Feb 19 '26 11:02

wutzebaer


1 Answers

I had a similar problem trying to position a progress bar behind other views. Switching to a FrameLayout with gravity="center" for both child views worked for me:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

   <ProgressBar
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:progress="50" />

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        ...
   </LinearLayout>
</FrameLayout>
like image 117
Andreas Gohr Avatar answered Feb 22 '26 02:02

Andreas Gohr