我有一个视图,其中包含一个顶视图(它是一个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>