【发布时间】:2017-07-02 15:01:10
【问题描述】:
我正在为我的 Android 布局而苦苦挣扎。
我想创建一个线性布局,它在顶部包含一个按钮,接下来是一个列表视图,当显示列表视图的所有元素时,我想显示一个显示谷歌地图的片段。
这是我的布局 xml 文件。在这种情况下,您只能看到 Fragment 和 Button 而看不到列表视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
tools:context="de.mypackage.MyActivity">
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
android:id="@+id/button_back"
android:text="@string/back"
/>
<ListView
android:id="@+id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"/>
/>
<fragment
android:id="@+id/fragement"
android:name="de.mpackage.MapsFragment"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
tools:layout="@layout/fragment_maps"/>
</LinearLayout>
知道如何实现我的布局吗?
【问题讨论】:
-
你可以将片段作为页脚添加到列表视图吗?
-
将标题添加到将保留按钮的列表视图。将页脚添加到将包含 Google 地图的列表视图。
-
@MichaelMeyer 我尝试将
wrap_content用于ListView,然后将layout_weight=1放入fragment。我发布了答案。希望能帮助到你。 :)
标签: android android-fragments layout