[英]Recycler View Not align Correctly with Tablayout
I am a fresher in android development,I applied tab layout with view pager,In Fragment i applied the Recycler view but an output Recyclerview Displaying Wrongly,Here i attached my recyclerview display like this 我在android开发中较新,我在视图分页器中应用了选项卡布局,在Fragment中,我应用了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"
/>
My Mainactivity.xml 我的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>
Firstly , set the height of relative layout as match_parent 首先,将相对布局的高度设置为match_parent
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/xvehiclelistRV"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
Secondly , If you want any view below of other view , always use layout_below in case of relative layout . 其次,如果要在其他视图下面找到任何视图,请在相对布局的情况下始终使用layout_below。 Or else you can use linear layout , and provide the orientation wither horizontal or vertical on the basis of your requirement . 否则,您可以使用线性布局,并根据您的要求提供水平或垂直方向。 This will place the view in order . 这将使视图井然有序。
<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.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_below="@+id/tabs"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>
Use this blog , for better understanding on linear and relative layout . 使用此博客,可以更好地了解线性和相对布局。 https://blog.mindorks.com/android-layout-relative-linear-frame https://blog.mindorks.com/android-layout-relative-linear-frame
Here is my Actvity Design :- 这是我的活动设计:
Replace code with Mainactivity.xml with my code :- 用我的代码用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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.