b.i
b.i

Reputation: 1107

android: ImageView is not displayed

I am using this layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#372c24" />

    <View
        android:id="@+id/space"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:background="@android:color/transparent" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:orientation="horizontal" 
        android:background="@drawable/shape_popup">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2" />
        <ImageView
            android:contentDescription="@string/app_name"
            android:id="@+id/rateStar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@drawable/image" />
    </LinearLayout>

</LinearLayout>

but the image is not displayed, why?

Upvotes: 0

Views: 1431

Answers (3)

Matt Clark
Matt Clark

Reputation: 28589

When you use the property:

android:background=""

It is usually looking for something like a color, such as #FFFF0000 <- Red, and it will not fill the container with the image.

To get an image into the container with proper fitting, you need to use the property:android:src="@drawable/..."

With this you can also use android:scaleType="..."

To change different scale types of the image within the container.

Upvotes: 1

Angel Solis
Angel Solis

Reputation: 511

You should use android:src instead of android:background like this:

<ImageView
        android:contentDescription="@string/app_name"
        android:id="@+id/rateStar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:src="@drawable/image" />

EDIT: Also you should set the android:layout_width to 0 since you are using the weight property:

        <ImageView
        android:contentDescription="@string/app_name"
        android:id="@+id/rateStar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:src="@drawable/image" />

Upvotes: 0

Android Killer
Android Killer

Reputation: 18489

ImageBiew wont display anything until it will get some source so use this

android:src="@drawable/image"

also modify your textview width as it is not needed as you are giving a weight.

          <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2" />

Upvotes: 1

Related Questions