У меня есть xml файл для компоновки каждой строки списка. У меня 3 столбца. В первом столбце изображение не отображается, только текст ниже.
Это мой 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>
Я получаю это (я рисую IMG, где должно появиться изображение):
Любые идеи?
Отметьте этот для своего пользовательского списка с изображениями и текстом.
Я столкнулся с той же проблемой в своем настраиваемом макете. Проблема заключалась в макете родителя, в котором было сохранено изображение. Я просто изменил линейный макет на относительный и сделал некоторые изменения в высоте и ширине, дал некоторое статическое значение, например height = 100dp и width = 100dp.
Если вы хотите, чтобы layout_weight для ImageView и TextView выполнялся, вам нужно установить layout_height равным нулю. Технически весовые суммы также должны содержать до 1, если вы также не устанавливаете weight_sum на родителя.
<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>
Если ваша деятельность расширяет AppCompatActivity
, вам следует использовать AppCompatImageView
вместо обычного ImageView
.