如何将recyclelerView添加到我的布局底部

时间:2018-01-02 14:02:05

标签: android xml android-layout

我想在底部添加RecyclerView到我的布局,但它处于错误的位置。

现在我有:

enter image description here

现在RecyclerView太落了,减少了一半的RecyclerView。我只想在我的布局底部使用RecyclerView,但我无法做到。

这是我的布局代码:

    <android.support.constraint.ConstraintLayout 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/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="showresultactivity.SlideTabsActivity">

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

    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="@+id/mapView"
        app:layout_constraintEnd_toEndOf="@+id/mapView"
        app:layout_constraintStart_toStartOf="@+id/mapView"
        app:layout_constraintTop_toTopOf="@+id/mapView" />



        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" /><!--this line make too far down, without it my recyclerview will be at the top of my layout-->
</android.support.constraint.ConstraintLayout>

我的RecyclerView布局:

<RelativeLayout 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/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"

tools:context="showresultactivity.SlideTabsActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewInfoWindowMarker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignWithParentIfMissing="true"
    >

</android.support.v7.widget.RecyclerView>

我的recyclerView行项目xml:

<RelativeLayout
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:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FCFCFC"
    tools:context="showresultactivity.SlideTabsActivity">


    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cardCornerRadius="3dp"
        app:cardElevation="1dp"
        android:layout_margin="5dp"
        app:cardPreventCornerOverlap="false">

        <RelativeLayout
            android:padding="8dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <ImageView
                android:id="@+id/imagesSrcUrl"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:src="@drawable/ic_launcher"
                android:scaleType="centerCrop" />


            <TextView
                android:id="@+id/first"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignStart="@+id/description"
                android:text="some text"
                android:textSize="20dp"
                android:textStyle="bold" />
            <TextView
                android:id="@+id/third"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/first"
                android:textSize="12dp"
                android:text="some text"
                android:layout_marginTop="5dp"
                android:gravity="right"
                android:textAlignment="gravity"
                />
            <TextView

                android:id="@+id/description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/imagesSrcUrl"
                android:layout_below="@id/first"
                android:textSize="12dp"
                android:text="some text"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                />




        </RelativeLayout>
    </android.support.v7.widget.CardView>



</LinearLayout>
<ImageButton
    android:layout_centerVertical="true"
    android:id="@+id/cardViewNext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:background="@drawable/circle_shape"
    android:src="@drawable/ic_next_black" />

<ImageButton
    android:layout_centerVertical="true"
    android:id="@+id/cardVievPrevious"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/circle_shape"
    android:src="@drawable/ic_previous_black" />

修改 我忘了我还有底部导航,回收器应该在底部地图但在底部导航上方。 底部导航布局:

    <?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"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="SlideTabsActivity"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    >

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/app_name">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TabItem
                android:id="@+id/tabItem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/tab_text_1" />

            <android.support.design.widget.TabItem
                android:id="@+id/tabItem2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/tab_text_2" />

            <android.support.design.widget.TabItem
                android:id="@+id/tabItem3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/tab_text_3" />

        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>


    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />



    <include layout="@layout/bottom_navigation_view" android:id="@+id/bottom_nav_view" />


</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

bottom_navigation_view:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/bottomRelativeLayout">
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/white_grey_border_bottom"

        app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

将此行添加到framelayout将有助于您实现这种定位:

app:layout_constraintBottom_toBottomOf="parent"

还要记住将框架布局的高度设置为: wrap content。上面这一行的目的是将框架布局固定/固定到约束布局的底部;任何最终的扩张都将是向上的。因此,框架布局的内容永远不会重叠。如果需要额外的空间,框架布局将向上投影,同时仍固定在约束布局的底部。

您可以在Constraint布局上查看更多XML属性的参考:https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html

PS:

您可以删除框架布局的android:layout_alignParentBottom="true"部分;它不再是必要的了