Android视图不显示

Android视图不显示,android,view,imageview,android-relativelayout,Android,View,Imageview,Android Relativelayout,我的应用程序中有这个布局,问题是,ID为overlay的ImageView没有显示在其他布局上,当我使用Android SDK Hierarchy viewer工具检查布局时,ImageView的高度为0,位于布局底部。我错过了什么?或者原因是什么 谢谢 注意:在相同条件下,当我使用按钮替换该视图时,不会出现此问题。但是它出现在视图或图像视图中 编辑:我使用前面提到的ImageView使整个视图略带红色,并将其用作ListView项 <RelativeLayout xmlns:androi

我的应用程序中有这个布局,问题是,ID为
overlay
ImageView
没有显示在其他布局上,当我使用Android SDK Hierarchy viewer工具检查布局时,
ImageView
的高度为0,位于布局底部。我错过了什么?或者原因是什么

谢谢

注意:在相同条件下,当我使用
按钮替换该视图时,不会出现此问题。但是它出现在
视图
图像视图

编辑:我使用前面提到的
ImageView
使整个视图略带红色,并将其用作
ListView

<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>

我想你需要做的是
android:layout\u alignParentCenter=“true”
而不是

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

@注意:所有内容都在View下,View是父类,无论是Button还是ImageView,ImageView的高度都是0,因为您没有设置任何源。修复这些错误您可以尝试以下方法:

<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" />


在imageview中,也不能同时指定所有路线类型 [1] .顶部为右或左
[2] .bottom,右键或左键。

这是我看到的xml(带有虚拟文本和图像)

这是你想要的吗?如果你没有看到这一点,我会感到惊讶

2.)如果这形成了单独的列表项xml,那么在主列表xml中,确保将其作为参数

android:layout_width="fill_parent"
android:layout_height="wrap_content"
或者您可能看不到此项目的边缘(文本和图像,您可能只看到红色覆盖,或者文本和图像可能重叠)

编辑:

如果这是您想要的,那么列表项现在会形成一个类似state的列表项

将代码修改为

  <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>


将图像和文本更改为运行时所需的内容

尝试删除android:layout\u alignParentBottom=“true”android:layout\u alignParentLeft=“true”android:layout\u alignParentRight=“true”android:layout\u alignParentTop=“true”您不能同时在两侧显示一个视图,即不右侧和不左侧。(由于同时设置了alignParentLeft和alignParentRight、top和bottom)。对我来说效果很好-尝试清理项目一次-对我来说,前景中的透明红色图像基本上覆盖了它后面的项目-这是你想要的吗?我为图像设置了一个源/为每个项目提供了一个虚拟文本them@Slartibartfast当前位置是的,这就是我想要的!我试着打扫,做了所有这些事情,但什么都没有做ing已更改。请查看我编写的编辑说明。视图声明后不必引用。如果在id前面使用+,甚至在下面的视图中也可以引用。检查此链接我有一个问题,如果宽度和高度是填充的,是否需要对齐?不必,但如果需要,请查看此xml代码您填写父级上一个imageview“@+id/覆盖”“的高度和宽度,它肯定会重叠另外2个视图。不起作用,我不同意您的描述。@KeyhanAsghari您的问题似乎不清楚。另外,您说
ImageView是一个高度为0的视图
,当您没有为ImageView设置任何图像时,您期望的高度是多少?最好设置分辨率。”urce/image检查准确的输出。@KeyhanAsghari也可以使用
android:layout_toLeftOf=“@+id/image”
在您的父布局的最顶层视图中查看当时的
@+id/image
id是未知的,因为您在文本视图之后声明了您的ImageView。关于1)是的,这是我想看到的,但我没有。现在已经差不多了。关于编辑部分)我知道,这解决了问题,还有其他方法。但是我想知道为什么我的代码不起作用。谢谢你详细的回答。
  <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>