【发布时间】:2018-02-18 17:37:59
【问题描述】:
我在MainActivity 中使用TabLayout,在第二个tab 里面我有一个RecyclerView,我成功地将数据绑定到RecyclerView,一切正常,但是当我将屏幕旋转到横向时模式回收器的最后一项正在被切断,
问题是这样的:
这是纵向模式:
和横向模式:
这是我的 XML 文件:
片段布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/cities_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
最后是 RecyclerView 项目:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="5dp"
android:elevation="3dp"
card_view:cardCornerRadius="3dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="250dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我尝试将 android:layout_marginBottom 添加到 de RecyclerView 但不起作用。
谢谢。
【问题讨论】:
-
只有一个 xml 用于横向和纵向模式的根视图(视图选项卡布局)?
-
是的,我只有一个。
-
使用带有线性布局子视图的滚动视图...包裹recyclerview...或者在recyclerview的底部留出边距
-
没有改变
-
为什么需要
android:scrollbars="none"?在我看来,您的项目在屏幕上没有足够的空间,并且由于您无法滚动,因此看起来视图正在“被切断”。
标签: android listview android-recyclerview