地图底部的 RecyclerView Android

RecyclerView at the bottom of Map Android

我正在尝试实现类似于 Field Trip 应用程序的功能,如下图所示:

下面是我的片段布局xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/map_recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:reverseLayout="true"
        android:divider="@null"
        android:layout_gravity="center_horizontal|bottom"/>
</FrameLayout>

但是我看不到 RecyclerView,而是 Map 占据了整个高度。

LinearLayout 放入 FrameLayout 并使用 weightSum;

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2.0" >

<com.google.android.gms.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/map_recyclerView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
     android:layout_weight="1"
    android:orientation="horizontal"
    app:reverseLayout="true"
    android:divider="@null"
    android:layout_gravity="center_horizontal|bottom"/>

</LinearLayout>

使用具有百分比权重的 LinearLayoutmaps 为 60%,RecyclerView 为 40%)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum = "1"
    android:orientation="vertical">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.60"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/map_recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight = "0.40"
        android:orientation="horizontal"
        app:reverseLayout="true"
        android:divider="@null"
        android:layout_gravity="center_horizontal|bottom"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/map_recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:layout_gravity="center_horizontal|bottom"
            android:orientation="horizontal"
            app:reverseLayout="true" />


    </RelativeLayout>

问题在于使用了 FrameLayout。把FrameLayout改成LinearLayout就好了。所以它应该是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/map_recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:reverseLayout="true"
        android:divider="@null"
        android:layout_gravity="center_horizontal|bottom"/>
</LinearLayout>

尝试使用 LinearLayout 并将 android:layout_weight="1" 提供给您的 <com.google.android.gms.maps.MapView 并将 android:layout_weight="1" 提供给您的 <android.support.v7.widget.RecyclerView 如下布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

  <com.google.android.gms.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

  <android.support.v7.widget.RecyclerView
    android:id="@+id/map_recyclerView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "1"
    android:orientation="horizontal"
    app:reverseLayout="true"
    android:divider="@null"
    android:layout_gravity="center_horizontal|bottom"/
    />
</LinearLayout>

在 mainLayout 中采用垂直方向的线性布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linearLayout"
        android:weightSum="2">

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/map_recyclerView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:divider="@null"
            android:orientation="horizontal"
            app:reverseLayout="true" />
    </LinearLayout>
</FrameLayout>

希望代码能帮到你