简体   繁体   English

android:图标中的图片未显示

[英]android: image in icon not showing

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. 谢谢。

The RelativeLayout here just makes it confusing. 这里的RelativeLayout令人困惑。 You can achieve this simply with a couple of LinearLayouts. 您可以简单地通过几个LinearLayouts来实现。 Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. 将横幅以height = wrap_content的水平布局包装,然后将ListView设置为height = fill_parent。 The list will then fill all available space. 然后,该列表将填充所有可用空间。 The List will scroll independently of the rest of the page. 列表将独立于页面的其余部分滚动。

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>

如果将RelativeLayout包裹在ScrollView ,并且由于ScrollView只能有一个孩子,将横幅放在上面怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM