我RecyclerView
内有两个ScrollView
。第二个RecyclerView
命名为" recyclerView
_ main_article"无法完全展示。我的意思是它的底部被切掉了。我试图添加名为&#34的额外视图;空"在RecyclerView
之下留出一些空间。我添加"空"," recyclerView
_ main_article"完全显示但是#34;空的"比它的高度短。
这是XML。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/view_title_line"
android:layout_width="5dp"
android:layout_height="24dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView_top_movie_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/top_movie_title"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
app:layout_constraintStart_toEndOf="@+id/view_title_line" />
<TextView
android:id="@+id/textView_see_all_movies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/see_all"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_main_video"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_title_line" />
<View
android:id="@+id/view_title_line2"
android:layout_width="5dp"
android:layout_height="24dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_video" />
<TextView
android:id="@+id/textView_top_article_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/top_article_title"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
app:layout_constraintStart_toEndOf="@+id/view_title_line2" />
<TextView
android:id="@+id/textView_see_all_articles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/see_all"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_main_article"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_title_line2" />
<!--<View
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:color/holo_orange_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_article" />-->
</android.support.constraint.ConstraintLayout>
</ScrollView>
我通过此Kotlin代码将HORIZONTAL应用于RecyclerViews。
recyclerView_main_video.layoutManager = LinearLayoutManager(this, OrientationHelper.HORIZONTAL, false)
recyclerView_main_article.layoutManager = LinearLayoutManager(this, OrientationHelper.HORIZONTAL, false)
我使用的是Android Studio 3.0.1,而我的recyclerview版本是26.1.0。
implementation 'com.android.support:recyclerview-v7:26.1.0'
我该怎么办?我需要你的帮助。
答案 0 :(得分:1)
在RecyclerView
中使用ScrollView
是一个坏主意,最佳做法是使用recyclerview
并将您想要的所有内容滚动到其中。如果您的回收商品上方有一些观看次数,只需使用自己的viewHolder
标题并将其放在recyclerView
的第一个位置
答案 1 :(得分:1)
将
ScrollView
更改为NestedScrollView
在第二个
中添加android:paddingBottom="50dp"
android:clipToPadding="false"
recyclerview
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/view_title_line"
android:layout_width="5dp"
android:layout_height="24dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView_top_movie_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/top_movie_title"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
app:layout_constraintStart_toEndOf="@+id/view_title_line" />
<TextView
android:id="@+id/textView_see_all_movies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/see_all"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_main_video"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_title_line" />
<View
android:id="@+id/view_title_line2"
android:layout_width="5dp"
android:layout_height="24dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_video" />
<TextView
android:id="@+id/textView_top_article_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/top_article_title"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
app:layout_constraintStart_toEndOf="@+id/view_title_line2" />
<TextView
android:id="@+id/textView_see_all_articles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/see_all"
app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_main_article"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:paddingBottom="50dp"
android:clipToPadding="false"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_title_line2" />
<!--<View
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:color/holo_orange_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_article" />-->
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
答案 2 :(得分:0)
尝试使用NestedScrollView
代替ScrollView