2

I have a xml file for layout of each row of listview. I have 3 columns. In first column the imageview doesn't show, only the text below it.

This is my row.xml:

<?xml version="1.0" encoding="utf-8"?>


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

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"  
    android:layout_height="fill_parent">

    <ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:gravity="center_vertical"
    android:layout_weight="1"
    android:src="@drawable/icon" />


     <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:layout_marginTop="5dip"
        android:text="hfghfgh"
    />


</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="fill_parent">

    <TextView android:layout_height="0dip" 
    android:gravity="center_vertical" 
    android:layout_weight="1" 
    android:text="fghfghfh" 
    android:id="@+id/cena1" 
    android:layout_width="fill_parent"/>

    <TextView
        android:id="@+id/cena2"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:layout_marginTop="5dip"
        android:text="gghj"
        />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" 
        android:id="@+id/razdalja"
        android:text="ghjghjgj"
        android:layout_marginTop="5dip"
        android:gravity="center_vertical"
        />


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

     <Button 

    android:background="@drawable/call_button"
    android:id="@+id/gumb_klic"        
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    android:layout_gravity="center_horizontal"     
    android:focusable="false"
    android:focusableInTouchMode="false"
        />
    </LinearLayout>

</LinearLayout>

What i get is this (i draw IMG where imageview should appear):

enter image description here

Any ideas?

DixieFlatline
  • 7,895
  • 24
  • 95
  • 147

4 Answers4

1

I faced the same issue in my custom layout. The problem was with the parent layout in which the images view was kept. I just changed the linear layout to relative and made some changes in the height and width , give some static value like height= 100dp and width = 100dp.

Rana Ranvijay Singh
  • 6,055
  • 3
  • 38
  • 54
1

Check this for your custom listview with Images and Text..

Venky
  • 11,049
  • 5
  • 49
  • 66
  • I know how to use it (the phone on the right is also an imageview and i shows correctly), but i guess i have problems with layout inside single row . – DixieFlatline Mar 24 '11 at 15:29
  • IMG image is not displaying for you? – Venky Mar 24 '11 at 15:30
  • In the Xml graphical Layout View that image is Visible.. you might made mistakes in Class file..Check it.. – Venky Mar 24 '11 at 15:33
  • In the graphical editor of layout in Eclipse, the image is shown but the text below it is squeezed and can be hardly seen. – DixieFlatline Mar 24 '11 at 15:42
  • Increase the Linear Layout Height. Instead of using this android:layout_height="?android:attr/listPreferredItemHeight" change android:layout_height="100dip" – Venky Mar 24 '11 at 15:49
1

If you want the layout_weight for the ImageView and TextView to be honored, you need to set the layout_height to zero. Technically the weight sums should also add up to 1 unless you are also setting weight_sum on the parent.

<LinearLayout
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"  
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="0px"
        android:adjustViewBounds="true"
        android:gravity="center_vertical"
        android:layout_weight=".5"
        android:src="@drawable/icon" 
    />

    <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight=".5"
        android:gravity="center_vertical"
        android:layout_marginTop="5dip"
        android:text="hfghfgh"
    />
</LinearLayout>
slund
  • 6,367
  • 2
  • 26
  • 19
  • Thank you for your example code. The problem was I did not have the android:adjustViewBounds attribute set to true. When I had the ImageView's layout_height set to wrap_content, it would size appropriately but still fill the entire screen's height when placed inside a table row. Big problems! Solved byu adding the android:adjustViewBounds="true" to the image view defined as: – Kevin Parker May 25 '11 at 19:03
1

If your activity extends AppCompatActivity, then you should use AppCompatImageView instead of ordinary ImageView.

zeroDivider
  • 1,050
  • 13
  • 29