[英]How to create a overlay layout upon a listview
I have a listview that will be filled with AsyncTask
and at the bottom edge of the app I need to show a fixed overlay layout like this: 我有一个将使用
AsyncTask
填充的列表视图,在应用程序的底部边缘,我需要显示一个固定的叠加布局,如下所示:
But I can't figure it out how I can do this in xml? 但我无法弄明白我如何在xml中做到这一点? This is my present layout.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>
As Daniel has suggested, use a RelativeLayout
because it allows stacking of components(same with FrameLayout
and SurfaceView
). 正如Daniel建议的那样,使用
RelativeLayout
因为它允许堆叠组件(与FrameLayout
和SurfaceView
相同)。 The following code will give you the layout you are looking for: 以下代码将为您提供所需的布局:
<?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>
In the code above, the color hex values used for transparentBlack
is #95000000
and white
is #ffffff
. 在上面的代码中,用于
transparentBlack
的颜色十六进制值是#95000000
而white
是#ffffff
。
Here is an excellent tutorial on the basics of UI design in android: Android User Interface Design: Layout Basics . 这是关于android中UI设计基础的优秀教程: Android用户界面设计:布局基础 。
Change the parent layout to RelativeLayout
or FrameLayout
and position the fixed view at the same level of the ListView
(but after the ListView
) 将父布局更改为
RelativeLayout
或FrameLayout
,并将固定视图定位在ListView
的同一级别(但在ListView
)
Something like: 就像是:
---> RelativeLayout
--> ListView
--> Any view as the fixed view
You can then align the fixed view to the bottom of the wrapping RelativeLayout
然后,您可以将固定视图与包装
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.