1

I have a list view and each item is rendered as follows

<?xml version="1.0" encoding="utf-8"?>
<!--  Single List Item Design -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"       
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip">

   <ImageView  
        android:id="@+id/projectImage"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/project_icon" 
        android:contentDescription = "@string/projectIcon" />       

   <LinearLayout
        android:id="@+id/projectDetails"
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="0dip">    

   <TextView
        android:id="@+id/topText"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:padding="10dip"
        android:textSize="16sp"
        android:textStyle="bold"        
        android:textColor="@color/text_color"
        android:gravity="center_vertical" />   

   <TextView
            android:id="@+id/bottomText"
            android:layout_width="fill_parent"
            android:layout_height="0dip"                
            android:paddingLeft="10dip"                
            android:textSize="14sp"         
            android:singleLine="true"           
            android:textColor="@color/locationText_color"
            android:ellipsize="marquee" />
   </LinearLayout>   
</LinearLayout>

But my listview is not rendered properly the list item is too short and it doesnt show any content See below

enter image description here

I do use custom styles. I also tried changing

android:layout_height="?android:attr/listPreferredItemHeight"

To

android:layout_height="100dip"

but it didnt work.

Can anyone help please.

2
  • 1
    Are you using a custom adapter? If yes how are you inflating the layout file in the getView method? Like this: inflater.inflate(R.layout.row_layout, parent, false)? Commented Jan 18, 2013 at 13:49
  • no i was using... inflater.inflate(R.layout.project_fragment_list, null) changed it to what you mentioned and it works :) but it doesnt show the two text views just shows image Commented Jan 18, 2013 at 13:53

2 Answers 2

2

First, as I said in my comment, you should always use this version of the inflate() method when you inflate the row layout file so you setup the right LayoutParams for the row view:

inflater.inflate(R.layout.row_layout, parent, false)

Regarding the two TextViews not appearing, I'm not sure how exactly do you want them to be placed. Here is what I think:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"       
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip">

   <ImageView  
        android:id="@+id/projectImage"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/project_icon" 
        android:contentDescription = "@string/projectIcon" />       

   <LinearLayout
        android:id="@+id/projectDetails"
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">    

   <TextView
        android:id="@+id/topText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:textSize="16sp"
        android:textStyle="bold"        
        android:textColor="@color/text_color"
        android:gravity="center_vertical" />   

   <TextView
            android:id="@+id/bottomText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"                
            android:paddingLeft="10dip"                
            android:textSize="14sp"         
            android:singleLine="true"           
            android:textColor="@color/locationText_color"
            android:ellipsize="marquee" />
   </LinearLayout>   
</LinearLayout>
Sign up to request clarification or add additional context in comments.

Comments

0

You have set the height of your TextViews to 0dp.

    android:layout_height="0dip"

Change it to wrap_content or set weights to your TextViews. The weight of the parent LinearLayout does not apply to them.

1 Comment

i tried it.. didnt work. I already have weight assigned to inner LinearLayout. That should be enough?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.