我有一个 ListView ,它将填充 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>
最佳答案
正如 Daniel 所建议的,使用 RelativeLayout
因为它允许堆叠组件(与 FrameLayout
和 SurfaceView
相同)。以下代码将为您提供所需的布局:
<?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 中 UI 设计基础知识的优秀教程:Android User Interface Design: Layout Basics .
关于android - 如何在 ListView 上创建覆盖布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17901862/