android - 如何在 ListView 上创建覆盖布局

标签 android overlay

我有一个 ListView ,它将填充 AsyncTask 并且在应用程序的底部边缘我需要显示一个固定的覆盖布局,如下所示:

enter image description here

但我不知道如何在 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>

最佳答案

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

<?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 的颜色十六进制值是 #95000000white#ffffff.

这是关于 Android 中 UI 设计基础知识的优秀教程:Android User Interface Design: Layout Basics .

关于android - 如何在 ListView 上创建覆盖布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17901862/

相关文章:

html - css 图像蒙版覆盖

image - FFMPEG:如何在 jpg 上叠加大尺寸 png

java - android: ConcurrentModificationException 与 map 覆盖

Android ShareActionProvider 在 Debug模式下工作,但在真实设备上不工作

android - 在 Android TV 上将 ProgressBar 添加到 DetailsOverviewRow

java - 线程在android中是如何工作的

android content activitynotfoundexception 没有找到处理 Intent 的 Activity - 当试图去 url

python-3.x - 如何使用 basemap Python 在背景之上绘制散点图

javascript - 将鼠标悬停在图像上时播放视频并显示文本

python - 是否可以在 Flutter 应用程序中运行 Python 解释器?