Android 如何在listview上创建覆盖布局

Android 如何在listview上创建覆盖布局,android,overlay,Android,Overlay,我有一个列表视图,其中将填充AsyncTask,在应用程序的底部边缘,我需要显示一个固定的覆盖布局,如下所示: 但我不知道如何在xml中实现这一点? 这是我当前的layout.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_par

我有一个列表视图,其中将填充
AsyncTask
,在应用程序的底部边缘,我需要显示一个固定的覆盖布局,如下所示:

但我不知道如何在xml中实现这一点? 这是我当前的layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

   <!-- Probably I need to do something here  -->

</LinearLayout>

将父布局更改为
RelativeLayout
FrameLayout
,并将固定视图定位在
列表视图
的同一级别(但在
列表视图
之后)

比如:

---> RelativeLayout
    --> ListView
    --> Any view as the fixed view
然后,您可以将固定视图与包装的底部对齐
RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <ListView
       android:id="@+id/list"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />

   <!-- Here you should position the fixed view  -->
</RelativeLayout>

正如Daniel所建议的,使用
相对视图
,因为它允许组件堆叠(与
框架布局
表面视图
相同)。以下代码将为您提供所需的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<RelativeLayout
   android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/transparentBlack"
    android:layout_alignParentBottom="true" >

   <TextView
       android:id="@+id/textView2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignBottom="@+id/textView1"
       android:layout_alignParentRight="true"
       android:layout_marginRight="20dp"
       android:text="Medium Text"
       android:textColor="@color/white"
       android:textAppearance="?android:attr/textAppearanceMedium" />

   <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_centerVertical="true"
       android:layout_marginLeft="40dp"
       android:text="Large Text"
       android:textAppearance="?android:attr/textAppearanceLarge"
       android:textColor="@color/white" />

   </RelativeLayout>

</RelativeLayout>

在上面的代码中,
transparentBlack
使用的颜色十六进制值是
#95000000
white
#ffffff


这是一个关于android用户界面设计基础的优秀教程:。

拿着这个:)谢谢,它工作得很好!我将阅读您提供的链接:)如果您希望能够滚动覆盖按钮上方最底部的项目,该怎么办?@l33t假设您正在使用
ArrayList
来保存列表对象。在此列表末尾添加一个
空的
间隔项。在适配器的
getView()
中(position==mArrayList.size-1),将
convertView的高度设置为覆盖的
height=>将convertView的可见性设置为
View.INVISIBLE
。尚未尝试过此方法-因此此方法可能需要一些修改。如果愿意,您可以使用最终实现编辑我的答案。