RecyclerView位于Android Android的底部

时间:2017-08-19 11:09:28

标签: android google-maps android-layout android-recyclerview android-cardview

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

enter image description here

下面是我的片段布局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占据了全高。

6 个答案:

答案 0 :(得分:3)

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>

答案 1 :(得分:3)

使用LinearLayout百分比权重(maps为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>

答案 2 :(得分:2)

尝试使用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>

答案 3 :(得分:1)

<?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>

答案 4 :(得分:1)

问题在于使用了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>

答案 5 :(得分:1)

在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>

希望代码可以帮助你