2016-02-28 155 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>