首页 > 解决方案 > 回收站视图未与 Tablayout 正确对齐

问题描述

我是 android 开发的新手,我应用了带有视图寻呼机的选项卡布局,在片段中我应用了 Recycler 视图但输出 Recyclerview 显示错误,这里我像这样附加了我的 recyclerview 显示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
    android:id="@+id/xvehiclelistRV"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    />

我的 Mainactivity.xml

 <include
    android:id="@+id/custom_actionbar"
    layout="@layout/custom_actionbar" />
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/custom_actionbar"
    android:background="@color/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#DCEBFF"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/colorPrimary"
        app:tabIndicatorHeight="2dp"
        app:tabSelectedTextColor="#696969"
        app:tabTextColor="@color/black"/>
</android.support.design.widget.AppBarLayout>

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

标签: javaandroidandroid-recyclerview

解决方案


这是我的活动设计:-

看看图片

用我的代码替换 Mainactivity.xml 的代码:-

<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/black"
        app:tabGravity="fill"
        app:tabIndicatorColor="@android:color/white"
        app:tabMode="fixed"
        app:tabSelectedTextColor="#FFF"
        app:tabTextColor="#FFF" />

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

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


推荐阅读