ImageView не отображается внутри пользовательской строки для просмотра списка - PullRequest
1 голос
/ 24 марта 2011

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

enter image description here

Есть идеи?

Ответы [ 4 ]

1 голос
/ 23 января 2019

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

1 голос
/ 25 марта 2011

Если вы хотите, чтобы 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>
1 голос
/ 27 февраля 2014

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

1 голос
/ 24 марта 2011

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...