ImageView не отображается внутри пользовательской строки для просмотра списка

1

У меня есть 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, где должно появиться изображение):

Изображение 174551

Любые идеи?

Теги:
listview
imageview

4 ответа

1
Лучший ответ

Отметьте этот для своего пользовательского списка с изображениями и текстом.

  • 0
    Я знаю, как его использовать (телефон справа также является изображением, и я показываю правильно), но я думаю, у меня есть проблемы с макетом внутри одной строки.
  • 0
    IMG изображение не отображается для вас?
Показать ещё 4 комментария
1

Я столкнулся с той же проблемой в своем настраиваемом макете. Проблема заключалась в макете родителя, в котором было сохранено изображение. Я просто изменил линейный макет на относительный и сделал некоторые изменения в высоте и ширине, дал некоторое статическое значение, например height = 100dp и width = 100dp.

1

Если вы хотите, чтобы 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>
  • 0
    Спасибо за ваш пример кода. Проблема была в том, что у меня не было атрибута android: AdjustViewBounds, установленного в true. Когда у меня в ImageView layout_height было установлено значение wrap_content, он подходил бы по размеру, но все равно занимал всю высоту экрана при размещении внутри строки таблицы. Большие проблемы! Решено, добавив android: AdjustViewBounds = "true" к представлению изображения, определенного как: <ImageView android: id = "@ + id / menuItem1" android: layout_height = "wrap_content" android: layout_width = "0dip" android: layout_weight = " .20 "android: AdjustViewBounds =" true "> </ ImageView>
0

Если ваша деятельность расширяет AppCompatActivity, вам следует использовать AppCompatImageView вместо обычного ImageView.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню