2011-12-14 40 views
0

我試圖在列表視圖的頂部放置一個橫幅,當列表向下滾動時,它停留在那裏。我目前的佈局實際上顯示了我想要的預覽,但是當我在模擬器中運行它時,唯一出現的就是列表。android:圖標不顯示

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

反正,我不明白爲什麼它不工作。有誰知道它可能是什麼?

謝謝。

+0

當你想堆意見,FrameLayout裏將要走的理想方式。試試看。如果使用它有困難,那麼有人會幫助你! – Abhijit 2011-12-14 23:11:39

+0

我試過了,它工作,謝謝! – djcmm476 2011-12-15 02:05:52

回答

1

這裏的RelativeLayout只是令人困惑。你可以簡單地用一對LinearLayouts實現這一點。用高度= wrap_content將橫幅包裝成水平佈局,並將ListView設置爲height = fill_parent。該列表將填充所有可用空間。列表將獨立於頁面的其餘部分進行滾動。

類似下面應該工作:

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

如果您將RelativeLayout包裝在ScrollView中,並且由於ScrollView只能有一個孩子,請將橫幅放在上面?