Kayhan Asghari
Kayhan Asghari

Reputation: 2854

Android view does not show up

I have this layout in my application, the problem is, the ImageView which has the ID overlay, does not show up over the others, and when I check the layout with Android SDK Hierarchy viewer tool, that ImageView has 0 height, placed at the bottom of the layout. What am I missing? Or what is the reason?

Thanks.

NOTE: This problem does not occur when I replace that view with a Button in the same condition. But it occurs with a View, or ImageView.

EDIT: I am using mentioned ImageView to make the whole view a bit reddish, and I'm using it as a ListView item.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/image" />

    <ImageView
        android:id="@id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"/>

    <ImageView
        android:id="@+id/overlay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#77ff0000" />

</RelativeLayout>

Upvotes: 0

Views: 5502

Answers (4)

Vrashabh Irde
Vrashabh Irde

Reputation: 14377

This is what I see with your xml(with dummy text and image)

enter image description here

1.) Is this what you want? I ll be surprised if you are not seeing this

2.) If this forms your individual list item xml then in your main list xml make sure you have this as your parameters

android:layout_width="fill_parent"
android:layout_height="wrap_content"

or you might not see the edges of this item (the text and the image and you might see only the red overlay, or the text and image might get overlapped)

EDIT:

If this is what you want - so that the list item now forms a list item like state then

enter image description here

Modify your code to

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/panda" />

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Stack Overflow"
        android:textColor="#ffffff" />


    <ImageView
        android:id="@+id/overlay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/image"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#77ff0000" />


</RelativeLayout>

Change Image and text to what you want at runtime

Upvotes: 1

Pinser
Pinser

Reputation: 1896

The height of the imageView is 0 because you havent set any source. Fixing these bugs you can try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"/>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/image" />

<ImageView
    android:id="@+id/overlay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="#77ff0000" />

Upvotes: -1

Miral Dhokiya
Miral Dhokiya

Reputation: 1710

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/image" />

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"/>

<ImageView
    android:id="@+id/overlay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="#77ff0000" />

In imageview you cant assign all the alignment type together either [1].top with right or left [2].bottom with right or left.

Upvotes: 1

Just Variable
Just Variable

Reputation: 877

I guess what you need to do is android:layout_alignParentCenter="true" instead of

android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"

@ NOTE: Everything comes under View which is a parent class whether its a Button or ImageView

Upvotes: 0

Related Questions