0

I have a progress bar and a text view inside of a frame layout. The text overlaps the progress bar.

The text view is twice the height of the progress bar (due to the length of the text) and i'd like the progress bar's height to auto-fit this.

I tried doing this by setting the progress bar to match_parent, and for the parent to wrap_content but the progress bar does not increase in height.

The XML is like so:

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

<ProgressBar  
    android:layout_width="match_parent"  
    style="?android:attr/progressBarStyleHorizontal"  
    android:layout_height="fill_parent"
    android:layout_gravity="center_horizontal|center_vertical"
/> 

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:text="Big long text here................................"    
    android:layout_gravity="center_horizontal|center_vertical"
/>

</FrameLayout>
1
  • match_parent and fill_parent?
    – Dominic
    Dec 4, 2012 at 13:23

2 Answers 2

5

Use a RelativeLayout and align the boundaries using layout_align.

 <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusable="false">
        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="Big long text here................................"
            android:layout_gravity="center_horizontal|center_vertical" />
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_height="fill_parent"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_alignTop="@id/textview"
            android:layout_alignLeft="@id/textview"
            android:layout_alignBottom="@id/textview" />
    </RelativeLayout>
1
  • 1
    I LOVE YOU. THANK YOU. The textview must be after the progressbar in the xml (to appear above it). This requires replacing android:layout_alignTop="@id/textview" etc in the progressbar tag with android:layout_alignTop="@+id/textview" (as the id is not yet defined). It works great!
    – user
    Jul 30, 2011 at 19:01
0

Use LinearLayout with android:layout_weight="1" for both ProgressBar and TextView. Something like this

<LinearLayout android:layout_height="match_parent"
 android:layout_width="match_parent"
 android:orientation="vertical> 
 <ProgressBar  
android:layout_width="match_parent"  
style="?android:attr/progressBarStyleHorizontal"  
android:layout_height="0dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/> 

<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="30sp"
android:text="Big long text here................................"    
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/>
</LinearLayout>

Why have you chose FrameLayout?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.