【问题标题】:Views under RecyclerView not being displayed (only shows in Android Studio preview)RecyclerView 下的视图不显示(仅在 Android Studio 预览中显示)
【发布时间】:2018-08-06 16:11:03
【问题描述】:

这已经让我发疯了一段时间了。我在它下面有一个 RecyclerView 和一个 TextView 。但是,我可以看到 RecyclerView 上方的所有内容,但下方没有。

以下是我的布局组成,我只是包含了相关代码

<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:layout_height="match_parent"
    android:layout_width="match_parent"
    >

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".HomeFragment">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_marginTop="@dimen/activity_vertical_margin"



<android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="40dp"
            android:layout_marginBottom="8dp"
            android:clipToPadding="false"
            android:scrollbars="horizontal"
            android:background="#f1f5f8"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/someTextView"

          />



<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:fontFamily="@font/droid_serif"
            android:text="@string/browse"
            android:textSize="18sp"
            android:layout_marginTop="40dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/recycler_view" />


    </android.support.constraint.ConstraintLayout>

</FrameLayout>

</android.support.v4.widget.NestedScrollView>

我尝试了一些我在互联网上找到的方法,比如用NestedScrollView 替换我原来的ScrollView,因为我的RecycleView 水平滚动但无济于事。

我也尝试将此app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到 XML 中的 RecyclerView 中,但输出相同。

我非常感谢任何帮助,因为我没有在互联网上找到任何案例或像我这样的案例。请注意,这不是完整的布局文件。 RecyclerView 上方还有其他视图,但这些视图显示没有任何问题,因此我没有放置它们的代码。如果您需要任何其他信息,请告诉我。

谢谢!

【问题讨论】:

    标签: android android-recyclerview android-nestedscrollview


    【解决方案1】:

    尝试将约束布局更改为线性布局(方向垂直)。 像这样

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical"
       >
    
    
    
             <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="40dp"
                android:layout_marginBottom="8dp"
                android:clipToPadding="false"
                android:scrollbars="horizontal"
                android:background="#f1f5f8"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/someTextView"
    
              />
    
    
    
              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:fontFamily="@font/droid_serif"
                android:text="@string/browse"
                android:textSize="18sp"
                android:layout_marginTop="40dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/recycler_view" />
    
    
        </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      为 RecyclereView 下面的 TextView 设置 id "bottomTextView" 和 为 RecyclerView 添加app:layout_constraintBottom_toTopOf="bottomTextView"

      【讨论】:

      • 分享您的布局的完整代码。你也可以使用 ConstraintLayout 的 RelativLayout。
      猜你喜欢
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多