繁体   English   中英

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

[英]How to add a recyclerView to the bottom of my layout

我想将底部的 RecyclerView 添加到我的布局中,但它的位置错误。

现在我有:

在此处输入图片说明

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

底部导航视图:

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

将此行添加到您的框架布局将帮助您实现该定位:

app:layout_constraintBottom_toBottomOf="parent"

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

您可以检查此以获取有关约束布局上更多 XML 属性的参考: https : //developer.android.com/reference/android/support/constraint/ConstraintLayout.html

PS:

您可以删除框架布局的android:layout_alignParentBottom="true"部分; 没有必要了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM