简体   繁体   中英

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

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只能有一个孩子,将横幅放在上面怎么办?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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