1

I have a ListView displaying some text on my android activity. The problem I am facing is that some text is bigger than the other so the ListView rows don't have the same size. I would like to have all the rows the size of the biggest. That way all the text will be display and they will all have the same size. Here is my xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

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

        <CheckBox
            android:id="@+id/favorite_checkbox"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            style="?android:attr/starStyle"
            android:layout_weight="1"
            />
    <TextView
        android:id="@+id/IdText"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        />

    <TextView
        android:id="@+id/StationNameText"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        />

    </LinearLayout>

</LinearLayout>

Thanks for your time.

user1594047
  • 181
  • 1
  • 1
  • 12

1 Answers1

0

You can get the height of the 'tallest' view programmatically - How to get an Android widget's size after layout is calculated?, and then set that height to your other layouts.

I would do something like this:

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;

int HeightOfTallestView = //method you choose from link above

IdText.setLayoutParams(new LinearLayout.LayoutParams(width, HeightOfTallestView ));

Please let me know if this works for you.

Community
  • 1
  • 1
Izak
  • 909
  • 9
  • 24