我的列表视图将填充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>
答案 0 :(得分:9)
正如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设计基础知识的优秀教程:Android User Interface Design: Layout Basics。
答案 1 :(得分:2)
将父级布局更改为RelativeLayout
或FrameLayout
,并将固定视图定位在ListView
的相同级别(但在ListView
之后)
类似的东西:
---> 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>