Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layout_height always wrapping content

it's just a simple question:

I have a layout file which is presented as an item inside of a ListView. I set the height of the RelativeLayout to 100dp, but it does not work, it's always wrapping the content, no matter which layout I use. What can I do to set a fixed value to the layout height without having it wrapping?

Thanks for the help.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="100dp"> <!-- this attribute seems to be ignored -->

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:orientation="horizontal"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_centerHorizontal="true">

        <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="@dimen/progressbar_small"
                 android:layout_height="@dimen/progressbar_small"
                 android:layout_gravity="center_vertical" />

        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="5dp"
                 android:text="@string/loading"
                 android:layout_gravity="center_vertical"
                 style="@style/ListItemSubtext" />

     </LinearLayout>
 </RelativeLayout>
like image 525
Flávio Faria Avatar asked Dec 28 '22 01:12

Flávio Faria


2 Answers

Do like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="100dip">
like image 77
notenking Avatar answered Jan 13 '23 19:01

notenking


I think in a list view all items are of the same height. In your case you could add the progress bar in the list footer view. Add a dummy height adjuster right before or after ListItemSubtext. Try using TableLayout instead of Relative and Linear Layout.

A dummy adjuster is like this.

<View android:layout_width="wrap_content" android:layout_height="100dip"/>

Please note you do not need xmlns in every element.

like image 44
dipu Avatar answered Jan 13 '23 19:01

dipu