0

I am using a simple ListView in which every item contain only a text field and nothing else. Here is my xml code for the list item:

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:layout_marginLeft="6dp"
            android:layout_marginRight="6dp"
            android:layout_marginTop="4dp"
            android:layout_marginBottom="4dp"
            android:background="@drawable/bg_card">


        <TextView
            android:id="@+id/txt"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:gravity="center_vertical"
            android:textSize="15sp"
            android:paddingLeft="6dip"
            android:textColor="#878787"
            android:textIsSelectable="true"/>

        </LinearLayout>

    </FrameLayout>

and here is my layout for the fragment using the list view.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#e5e5e5">

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:dividerHeight="0dp"
        android:divider="@null"/>

    </RelativeLayout>

Now, while creating an object of the adapter in my fragment like this

Level weather_data[] = new Level[] {
    new Level(R.drawable.s1, 
              "Some text which will be present in the list item",      
              R.drawable.play_button)
        };

If I have a very long sentence in the second parameter ie the text, some part of it does not get displayed and the sentence is displayed incomplete in the list item.

I have tried using android:minHeight to change the height of the list item but it didn't work. What could be the solution to this? Thanks

Sam Hosseini
  • 807
  • 9
  • 17
Shivam Bhalla
  • 1,739
  • 4
  • 34
  • 62

2 Answers2

0

It suffices to set the container to wrap_content and it will be resized when need. Your shown layout is not complete and I simply suspect that you may have something hardfixed here:

android:layout_height="?android:attr/listPreferredItemHeight

Also there's no real point in you layout to wrap TextView in LinearLayout and then all in FrameLayout. You can get the same effect with padding and bg moved to FrameLayout

Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
0

try to set wrap_content instead of "?android:attr/listPreferredItemHeight" within android:layout_height.

Something like this:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
Peter Moskala
  • 362
  • 1
  • 9