Reputation: 8035
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):
Any ideas?
Upvotes: 2
Views: 3423
Reputation: 1089
If your activity extends AppCompatActivity
, then you should use AppCompatImageView
instead of ordinary ImageView
.
Upvotes: 1
Reputation: 6155
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.
Upvotes: 1
Reputation: 6397
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>
Upvotes: 1