【问题标题】:ScrollView not displaying all Contents in HomefragmentScrollView 不显示 Homefragment 中的所有内容
【发布时间】:2018-07-22 13:35:16
【问题描述】:

我正在尝试禁用滚动视图并显示主页中的所有内容,但是直到没有运气滚动才显示所有内容。我已经尝试了有关此的所有问题,但仍然没有运气。如果有人可以帮助我,我将不胜感激。谢谢:)

这里是fragment_home.xml..

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg">

    <ProgressBar
        android:id="@+id/progressBar"
        style="@style/Widget.AppCompat.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="gone" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <FrameLayout
                android:id="@+id/ContainerSlider"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_latest"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_featured"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp" />

        </LinearLayout>
    </ScrollView>


</RelativeLayout>

【问题讨论】:

  • 禁用滚动视图是什么意思?另外,为什么需要两个 recyclerview?
  • 意味着如果启用滚动视图,我想显示 fragment_home 中的所有内容,然后我认为内容不显示。
  • 你不需要带有 recyclerview 的滚动视图。您的布局应该可以使用单个回收器视图
  • 你能帮我让代码在没有滚动视图的情况下工作吗?
  • 是的,如果你能与我分享一个关于你想要实现的粗略设计/草图

标签: android android-layout android-fragments android-xml


【解决方案1】:

您是否尝试添加到滚动视图

android:fillportView="true"

你也不需要两个 recyclerview.. 一个有多种视图类型。

话虽如此,您也不需要该滚动视图。您只需要一个具有多种视图类型的回收视图。

【讨论】:

  • 您的 recyclerview 物品是否已定义高度?
  • 是的 recyclerview 有 match_parent 高度。
  • 不,不是recyclerview。回收者查看项目。他们应该有一个定义的高度才能工作。尝试以 dp 为单位定义高度。
  • 我看到您将我的答案标记为正确。这是否意味着我解决了你的问题?
【解决方案2】:

使用来自 airbnb 的库 EPOXY 可以很好地处理您的布局。 会让你的生活轻松很多。 https://github.com/airbnb/epoxy

【讨论】:

    【解决方案3】:

    您是否尝试过改用NestedScrollView

    LinearLayout 的高度也应为match_parent 而不是wrap_content

    此外,您应该只将weight 用于LinearLayout 的子视图,以便为NestedScrollView 删除它。

    <NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    

    【讨论】:

    • 检查了 NestedScrollView 仍然没有显示所有内容。
    • 你做了 LinearLayout match_parent 吗?还将 android:fillportView="true" 添加到 NestedScrollView。
    • 是的,宽度和高度都是 match_parent。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多