2016-02-28 70 views
1

我有一個視圖,其中包含一個頂視圖(這是一個mapview,但它尚未實現)和它下面的列表視圖。Android的listview覆蓋另一個視圖

我想要做的是讓頂部視圖的頂部覆蓋頂部視圖的底部一點點。這是類似於我想要實現的東西:

enter image description here

(無標籤頭和圖像會的MapView)

我不知道我怎樣才能實現那,這裏是我迄今爲止:

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

    <View 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:background="@android:color/holo_red_dark"> 

    </View> 

    <com.hmm.widgets.CustomListView 
     android:id="@+id/runners_list" 
     android:background="@android:color/darker_gray" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:dividerHeight="10dp" 
     android:divider="@android:color/darker_gray"> 

    </com.hmm.widgets.CustomListView> 

</RelativeLayout> 

我試過負邊界,這沒有奏效。我不確定我該如何實現類似的功能。我應該使用FrameLayout嗎?

+0

我加入RelativeLayout的替代解決方案。 –

+0

你是如何獲得該列表視圖頂部的填充以顯示圖像的? – mastrgamr

回答

2

您可以在您的案例中使用LinearLayout並像這樣設計佈局。這是一種消極的layout_marginTop設置爲自定義ListView

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

    <View 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:background="@android:color/holo_red_dark"> 

    </View> 

    <com.hmm.widgets.CustomListView 
     android:id="@+id/runners_list" 
     android:background="@android:color/darker_gray" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="@dimen/activity_vertical_margin" 
     android:layout_marginRight="@dimen/activity_vertical_margin" 
     android:dividerHeight="10dp" 
     android:layout_marginTop="-40dp" 
     android:divider="@android:color/darker_gray"> 

    </com.hmm.widgets.CustomListView> 

</LinearLayout> 
+0

這很奇怪。我做了同樣的事情,但唯一的區別是我的觀點和lisview有分量。也許這就是原因。我會嘗試這個,並會讓你知道。謝謝 –

0

補充Reaz's answer的一招,你可以用RelativeLayout做到這一點,而無需使用負利潤率(這是有點controversial)。

請注意CustomListView中的最後四個屬性:您使用alignParent*約束高度,設置一個虛擬高度,該高度將被丟棄,並使用空白從頂部偏移視圖。 「負抵消」將爲250dp - 200dp = 50 dp

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

    <View 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:background="@android:color/holo_red_dark"> 

    </View> 

    <com.hmm.widgets.CustomListView 
     android:id="@+id/runners_list"  
     android:background="@android:color/darker_gray" 
     android:layout_width="match_parent" 
     android:dividerHeight="10dp" 
     android:divider="@android:color/darker_gray" 

     android:layout_height="0dp" 
     android:layout_marginTop="200dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true"> 
    </com.hmm.widgets.CustomListView> 
</RelativeLayout> 

相關問題