android:图像中没有显示图标

时间:2022-09-01 09:36:26

I'm trying to place a banner at the top of a listview, one that stays there when the list scrolls down. The layout I currently have actually show what I want in the preview but when I run it in the emulator the only thing that appears is the list.

我正试图在列表视图的顶部放置一个横幅,当列表向下滚动时,横幅保持在那里。我目前的布局实际上在预览中显示了我想要的内容,但是当我在模拟器中运行时,唯一出现的是列表。

The XML is:

XML是:

<?xml version="1.0" encoding="utf-8"?>

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

    <ImageView android:src="@drawable/edinburghcrest"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:id="@+id/EdUniCrest" android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"></ImageView>
    <TextView android:layout_height="wrap_content" android:id="@+id/banner"
    android:text="Hotels Nearby" android:textColor="#FFFFFF"
    android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
    android:layout_alignParentTop="true" android:layout_toRightOf="@+id/EdUniCrest"
    android:layout_alignParentRight="true" android:layout_alignBottom="@+id/EdUniCrest"
    android:background="#25476C"></TextView>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:background="@color/listcolor" android:orientation="vertical" android:layout_marginTop="50dp">

            <ListView android:id="@android:id/list" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
            </ListView>

    <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="@string/no_lunchs" />

</LinearLayout>

Anyway, I can't see why it isn't working. Does anyone have any idea what it might be?

无论如何,我不明白为什么它不起作用。有谁知道它可能是什么?

Thanks.

谢谢。

2 个解决方案

#1


1  

The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.

这里的RelativeLayout让它变得混乱。您只需使用几个LinearLayouts即可实现此目的。使用height = wrap_content将横幅包裹在水平布局中,并将ListView设置为height = fill_parent。然后该列表将填充所有可用空间。列表将独立于页面的其余部分滚动。

Something like below should work:

下面的东西应该工作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout android:orientation="horizontal" android:id="@+id/bannerBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView android:src="@drawable/edinburghcrest"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:id="@+id/EdUniCrest"/>
       <TextView android:layout_height="wrap_content" android:id="@+id/banner"
            android:text="Hotels Nearby" android:textColor="#FFFFFF"
            android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
            android:background="#25476C"/>
     </LinearLayout>
     <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    <TextView android:id="@android:id/empty" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="@string/no_lunchs" />
</LinearLayout>

#2


0  

What if you wrapped your RelativeLayout in a ScrollView, and since a ScrollView can only have one child, put the banner above it?

如果您将RelativeLayout包装在ScrollView中,并且由于ScrollView只能有一个子节点,请将横幅置于其上方,该怎么办?

#1


1  

The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.

这里的RelativeLayout让它变得混乱。您只需使用几个LinearLayouts即可实现此目的。使用height = wrap_content将横幅包裹在水平布局中,并将ListView设置为height = fill_parent。然后该列表将填充所有可用空间。列表将独立于页面的其余部分滚动。

Something like below should work:

下面的东西应该工作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout android:orientation="horizontal" android:id="@+id/bannerBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView android:src="@drawable/edinburghcrest"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:id="@+id/EdUniCrest"/>
       <TextView android:layout_height="wrap_content" android:id="@+id/banner"
            android:text="Hotels Nearby" android:textColor="#FFFFFF"
            android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
            android:background="#25476C"/>
     </LinearLayout>
     <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    <TextView android:id="@android:id/empty" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:text="@string/no_lunchs" />
</LinearLayout>

#2


0  

What if you wrapped your RelativeLayout in a ScrollView, and since a ScrollView can only have one child, put the banner above it?

如果您将RelativeLayout包装在ScrollView中,并且由于ScrollView只能有一个子节点,请将横幅置于其上方,该怎么办?