【问题标题】:ScrollView is not working for my layoutScrollView 不适用于我的布局
【发布时间】:2016-04-12 10:52:37
【问题描述】:

下面是我的 xml 文件,其中包含 ScrollView,但滚动不起作用,当我运行我的程序 RecyclerView(底部)时,项目在 ScrollView 被删除时显示的 UI 显示中丢失。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#fff">

    <ImageView
        android:id="@+id/movie_image"
        android:layout_width="250px"
        android:layout_height="300px"
        android:layout_alignParentLeft="true"
        android:scaleType="centerCrop"
        android:src="@drawable/jellybean"/>

    <!-- title Label -->
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/movie_image"
        android:paddingLeft="20dip"
        android:textColor="@color/black"
        android:text="Title "
        android:singleLine="true"
        android:ellipsize="end"
        android:textSize="18sp"
        android:textStyle="bold" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/popularity_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingBottom="10dp"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/title">

        <!-- popularity label -->
        <ImageView
            android:id="@+id/star1"
            android:layout_width="45px"
            android:layout_height="45px"
            android:layout_toRightOf="@+id/popularity"
            android:src="@drawable/blank_star" />
        <ImageView
            android:id="@+id/star2"
            android:layout_width="45px"
            android:layout_height="45px"
            android:layout_toRightOf="@+id/star1"
            android:src="@drawable/blank_star"/>
        <ImageView
            android:id="@+id/star3"
            android:layout_width="45px"
            android:layout_height="45px"
            android:layout_toRightOf="@+id/star2"
            android:src="@drawable/blank_star"/>
        <ImageView
            android:id="@+id/star4"
            android:layout_width="45px"
            android:layout_height="45px"
            android:layout_toRightOf="@+id/star3"
            android:scaleType="centerCrop"
            android:src="@drawable/blank_star"/>
        <ImageView
            android:id="@+id/star5"
            android:layout_width="45px"
            android:layout_height="45px"
            android:layout_toRightOf="@+id/star4"
            android:src="@drawable/blank_star"/>

    </RelativeLayout>

    <!-- tagline label -->
    <TextView
        android:id="@+id/tagline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="tagline"
        android:paddingLeft="20dip"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/popularity_list"
        android:textColor="@color/black" />

    <!-- release date label -->
    <TextView
        android:id="@+id/release_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="20dip"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/tagline"
        android:text="date "
        android:textColor="@color/black" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/budget_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dip"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/release_date">

        <!-- Budget label -->
        <TextView
            android:id="@+id/budget_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Budget : "
            android:textColor="@color/black" />
        <TextView
            android:id="@+id/budget"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/budget_text"
            android:text="budget "
            android:textColor="@color/black" />
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/revenue_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dip"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/budget_group">

        <!-- Revenue label -->
        <TextView
            android:id="@+id/revenue_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Revenue : "
            android:textColor="@color/black" />
        <TextView
            android:id="@+id/revenue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/revenue_text"
            android:text="revenue "
            android:textColor="@color/black" />
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/status_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dip"
        android:orientation="horizontal"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/revenue_group">

        <!-- Movie status label -->
        <TextView
            android:id="@+id/status_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Status : "
            android:textColor="@color/black" />
        <TextView
            android:id="@+id/status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/status_text"
            android:text="status "
            android:textColor="@color/black" />
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Vote_count_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="10dip"
        android:layout_below="@+id/movie_image">

        <!-- favourites label -->
        <ImageView
            android:id="@+id/favourites"
            android:layout_width="50px"
            android:layout_height="50px"
            android:scaleType="centerCrop"
            android:src="@drawable/blank_star"/>

        <TextView
            android:id="@+id/opening_brac"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/favourites"
            android:paddingLeft="10dip"
            android:text="("
            android:textColor="@color/black" />

        <!-- Vote average label -->
        <TextView
            android:id="@+id/votes_avg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/opening_brac"
            android:text="Votes_avg "
            android:paddingBottom="2dip"
            android:textColor="@color/black" />

        <TextView
            android:id="@+id/after_vote_avg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/votes_avg"
            android:text="/10)"
            android:textColor="@color/black" />

        <!-- Total vote counts label -->
        <TextView
            android:id="@+id/votes_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/after_vote_avg"
            android:layout_toRightOf="@+id/favourites"
            android:paddingLeft="10dip"
            android:text="count"
            android:textColor="@color/black" />

        <TextView
            android:id="@+id/closing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/after_vote_avg"
            android:layout_toRightOf="@+id/votes_count"
            android:text=" users."
            android:textColor="@color/black" />

        <!-- Overview label -->
        <TextView
            android:id="@+id/overview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/closing"
            android:text="Overview"
            android:paddingTop="20dp"
            android:textColor="@color/black" />
    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fav_watchlist_icons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="10dip"
        android:gravity="center"
        android:layout_below="@+id/Vote_count_list">

        <!-- My favourite icon and text group -->
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/fav_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="10dip">

            <ImageView
                android:id="@+id/fav_icon"
                android:layout_width="160px"
                android:layout_height="160px"
                android:scaleType="centerCrop"
                android:src="@drawable/favorite_disable_normal"/>

            <TextView
                android:id="@+id/fav_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/fav_icon"
                android:paddingRight="20dp"
                android:paddingTop="10dp"
                android:text="My Favourite"
                android:textColor="@color/black" />
        </RelativeLayout>

        <!-- My watchlist icon and text group -->
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/watchlist_icons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="10dip"
            android:layout_toRightOf="@+id/fav_group">

            <ImageView
                android:id="@+id/watchlist_icon"
                android:layout_width="160px"
                android:layout_height="160px"
                android:scaleType="centerCrop"
                android:src="@drawable/watchlist_disable_normal"/>

            <TextView
                android:id="@+id/watchlist_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="20dp"
                android:paddingTop="10dp"
                android:text="My Watchlist"
                android:layout_below="@id/watchlist_icon"
                android:textColor="@color/black" />
        </RelativeLayout>

    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/poster_list"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="15dip"
        android:layout_below="@+id/fav_watchlist_icons">

        <!--  Recycler View  -->
        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/recycler_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="none" />

    </RelativeLayout>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/trailor_list"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:layout_below="@+id/poster_list">

        <!--  Recycler View for Video links -->
        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/recycler_view_trailers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="none" />

    </RelativeLayout>

    </RelativeLayout>

</ScrollView> 

我在其他帖子中看到提到 ScrollView 应该包裹在我已经完成的单个对象上,但它仍然无法正常工作。

【问题讨论】:

  • 漂亮的疯狂布局,没读完,但看起来有些文本视图会相互重叠,无论如何,嵌套滚动总是很棘手,你应该看看这样的东西:developer.android.com/intl/es/reference/android/support/v4/…
  • 回收器视图本身就是滚动组件,这就是它们在滚动视图中表现不佳的原因
  • 设置为ScrollView : android:layout_height="match_parent"
  • @Nanoc,项目没有重叠,我可以在手机显示屏上看到它们,不确定最后一个回收视图,因为滚动不起作用。
  • @Vladimir,尝试设置 ScrollView : android:layout_height="match_parent" 但仍然无法正常工作

标签: android android-layout scrollview


【解决方案1】:

试试下面的-

  1. 将所有相关布局设为线性布局的子布局(经过一些研究发现它是正确的方式)。
  2. 为您的 ScrollView 布局设置一个最小高度 (android:minHeight)。

它应该可以工作。

【讨论】:

  • 不走运,滚动仍然无法正常工作,一旦我将 ScrollView 添加到我的 xml 中,在 Android 预览本身中,我可以看到 Recycler 视图项丢失。
  • 我可以在我的布局中清楚地看到这一点。尝试在布局中添加一些项目。有时工作室不能完美地渲染布局。静态添加项目以进行测试后,在您的设备上运行项目。我很久以前就遇到过同样的问题,并且只使用上面的方法解决了。
  • 你是否也尝试过使用 RecyclerView,这似乎是罪魁祸首,我也曾在手机上尝试过。
  • 应该不是罪魁祸首。和我一起工作得很好。即使在布局中也显示回收视图。
  • 你能分享你的xml吗?
【解决方案2】:

我遇到了同样的问题。其实主要问题是滚动视图。

Note: 不要使用滚动视图作为父级。只需在父布局中获取滚动视图,即 LinearLayout 或 RelativeLayout。

试试这样的:

<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:background="#fff">

        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

        <ImageView
            android:id="@+id/movie_image"
            android:layout_width="250px"
            android:layout_height="300px"
            android:layout_alignParentLeft="true"
            android:scaleType="centerCrop"
            android:src="@drawable/jellybean"/>

        <!-- title Label -->
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/movie_image"
            android:paddingLeft="20dip"
            android:textColor="@color/black"
            android:text="Title "
            android:singleLine="true"
            android:ellipsize="end"
            android:textSize="18sp"
            android:textStyle="bold" />

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/popularity_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingBottom="10dp"
            android:orientation="horizontal"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/title">

            <!-- popularity label -->
            <ImageView
                android:id="@+id/star1"
                android:layout_width="45px"
                android:layout_height="45px"
                android:layout_toRightOf="@+id/popularity"
                android:src="@drawable/blank_star" />
            <ImageView
                android:id="@+id/star2"
                android:layout_width="45px"
                android:layout_height="45px"
                android:layout_toRightOf="@+id/star1"
                android:src="@drawable/blank_star"/>
            <ImageView
                android:id="@+id/star3"
                android:layout_width="45px"
                android:layout_height="45px"
                android:layout_toRightOf="@+id/star2"
                android:src="@drawable/blank_star"/>
            <ImageView
                android:id="@+id/star4"
                android:layout_width="45px"
                android:layout_height="45px"
                android:layout_toRightOf="@+id/star3"
                android:scaleType="centerCrop"
                android:src="@drawable/blank_star"/>
            <ImageView
                android:id="@+id/star5"
                android:layout_width="45px"
                android:layout_height="45px"
                android:layout_toRightOf="@+id/star4"
                android:src="@drawable/blank_star"/>

        </RelativeLayout>

        <!-- tagline label -->
        <TextView
            android:id="@+id/tagline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="tagline"
            android:paddingLeft="20dip"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/popularity_list"
            android:textColor="@color/black" />

        <!-- release date label -->
        <TextView
            android:id="@+id/release_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="20dip"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/tagline"
            android:text="date "
            android:textColor="@color/black" />

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/budget_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dip"
            android:orientation="horizontal"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/release_date">

            <!-- Budget label -->
            <TextView
                android:id="@+id/budget_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Budget : "
                android:textColor="@color/black" />
            <TextView
                android:id="@+id/budget"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/budget_text"
                android:text="budget "
                android:textColor="@color/black" />
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/revenue_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dip"
            android:orientation="horizontal"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/budget_group">

            <!-- Revenue label -->
            <TextView
                android:id="@+id/revenue_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Revenue : "
                android:textColor="@color/black" />
            <TextView
                android:id="@+id/revenue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/revenue_text"
                android:text="revenue "
                android:textColor="@color/black" />
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/status_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dip"
            android:orientation="horizontal"
            android:layout_toRightOf="@+id/movie_image"
            android:layout_below="@+id/revenue_group">

            <!-- Movie status label -->
            <TextView
                android:id="@+id/status_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Status : "
                android:textColor="@color/black" />
            <TextView
                android:id="@+id/status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/status_text"
                android:text="status "
                android:textColor="@color/black" />
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/Vote_count_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="10dip"
            android:layout_below="@+id/movie_image">

            <!-- favourites label -->
            <ImageView
                android:id="@+id/favourites"
                android:layout_width="50px"
                android:layout_height="50px"
                android:scaleType="centerCrop"
                android:src="@drawable/blank_star"/>

            <TextView
                android:id="@+id/opening_brac"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/favourites"
                android:paddingLeft="10dip"
                android:text="("
                android:textColor="@color/black" />

            <!-- Vote average label -->
            <TextView
                android:id="@+id/votes_avg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/opening_brac"
                android:text="Votes_avg "
                android:paddingBottom="2dip"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/after_vote_avg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/votes_avg"
                android:text="/10)"
                android:textColor="@color/black" />

            <!-- Total vote counts label -->
            <TextView
                android:id="@+id/votes_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/after_vote_avg"
                android:layout_toRightOf="@+id/favourites"
                android:paddingLeft="10dip"
                android:text="count"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/closing"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/after_vote_avg"
                android:layout_toRightOf="@+id/votes_count"
                android:text=" users."
                android:textColor="@color/black" />

            <!-- Overview label -->
            <TextView
                android:id="@+id/overview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/closing"
                android:text="Overview"
                android:paddingTop="20dp"
                android:textColor="@color/black" />
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/fav_watchlist_icons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="10dip"
            android:gravity="center"
            android:layout_below="@+id/Vote_count_list">

            <!-- My favourite icon and text group -->
            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/fav_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="10dip">

                <ImageView
                    android:id="@+id/fav_icon"
                    android:layout_width="160px"
                    android:layout_height="160px"
                    android:scaleType="centerCrop"
                    android:src="@drawable/favorite_disable_normal"/>

                <TextView
                    android:id="@+id/fav_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/fav_icon"
                    android:paddingRight="20dp"
                    android:paddingTop="10dp"
                    android:text="My Favourite"
                    android:textColor="@color/black" />
            </RelativeLayout>

            <!-- My watchlist icon and text group -->
            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/watchlist_icons"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="10dip"
                android:layout_toRightOf="@+id/fav_group">

                <ImageView
                    android:id="@+id/watchlist_icon"
                    android:layout_width="160px"
                    android:layout_height="160px"
                    android:scaleType="centerCrop"
                    android:src="@drawable/watchlist_disable_normal"/>

                <TextView
                    android:id="@+id/watchlist_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="20dp"
                    android:paddingTop="10dp"
                    android:text="My Watchlist"
                    android:layout_below="@id/watchlist_icon"
                    android:textColor="@color/black" />
            </RelativeLayout>

        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/poster_list"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="15dip"
            android:layout_below="@+id/fav_watchlist_icons">

            <!--  Recycler View  -->
            <android.support.v7.widget.RecyclerView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/recycler_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scrollbars="none" />

        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/trailor_list"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="5dip"
            android:layout_below="@+id/poster_list">

            <!--  Recycler View for Video links -->
            <android.support.v7.widget.RecyclerView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/recycler_view_trailers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scrollbars="none" />

        </RelativeLayout>
            </RelativeLayout>
        </ScrollView>
    </RelativeLayout>

【讨论】:

  • RecyclerView 似乎是真正的罪魁祸首,我尝试了以下更改:
  • 限制了 ScrollView 的高度,可以在该高度内滚动但 RecyclerView 项目丢失
  • 好的,让我更深入地了解您的代码。还有一件事不要在RelativeLayout 中使用方向。方向仅适用于 LinearLayout。
【解决方案3】:

ScrollView 只能有一个子视图或 ViewGroup。

在您的布局中,您有 2 个相对布局子级。因此将两者合并为一个 ViewGruop。

将 ScrollView 的宽度和高度设置为 fill_parent

【讨论】:

    【解决方案4】:

    在滚动视图中使用 android:fillViewPort:true

    【讨论】:

    • 试过了,现在 RecyclerView 也显示了,但 Scroll 仍然无法工作(之前的 RecyclerView 在 ScrollView 添加到活动时丢失)。
    • 在滚动视图标签之间采用一个垂直线性布局......所有这些线性布局标签之间的相对布局代码......希望它能工作......你必须做这是因为滚动视图只能有一个子布局 ....但在你的情况下,你有两个子相对布局
    • 也试过了,将所有相关布局放在一个 LinearLayout 下,并将 Scroll View 放在上面,但这也不起作用......顺便说一句,在我上面发布的 xml 中,RelativeLayout 仅在顶端提到在底部,因此使其成为 Scroll View 的单个对象。
    【解决方案5】:

    您可以使用 android:fillViewport="true" 让 NestedScrollView 测量 RecyclerView。 RecyclerView 将填充剩余的高度。所以如果你想滚动 NestScrollView,你可以设置 RecyclerView 的 minHeight。

    请参考以下链接: How to use RecyclerView inside NestedScrollView?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      相关资源
      最近更新 更多