簡體   English   中英

Android ListView覆蓋另一個視圖

[英]Android listview to overlay another view

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

我想做的是使列表視圖的頂部稍微覆蓋一下頂部視圖的底部。 這與我要實現的目標類似:

在此處輸入圖片說明

(沒有標簽頁眉,圖像將是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嗎?

您可以在您的情況下使用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>

補充Reaz的答案 ,您也可以使用RelativeLayout做到這一點,而無需使用負邊距(這有爭議 )。

請注意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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM