我有一个视图,它包含一个顶视图(它是一个mapview,但还没有实现)和一个下面的listview。
我要做的是使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=50dp
。
<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>
null