【问题标题】:Recyclerview along with other views Strange BehaviourRecyclerview 以及其他视图奇怪的行为
【发布时间】:2016-11-20 11:08:35
【问题描述】:

我有 recyclerview 以及 NestedScrollView 中的其他卡片视图

这是完整的xml

<?xml version="1.0" encoding="utf-8"?><FrameLayout
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"
tools:ignore="MissingPrefix"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="@dimen/home_content_padding">

            <android.support.v7.widget.CardView
                android:id="@+id/card_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cardBackgroundColor="?attr/card_background"
                app:cardUseCompatPadding="true"
                app:cardElevation="@dimen/card_home_elevation"
                app:cardCornerRadius="@dimen/card_home_corner_radius"
                app:contentPadding="@dimen/card_home_content_padding">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="?android:attr/textColorPrimary"
                    android:textSize="14sp"
                    android:text="@string/home_description"
                    fontPath="fonts/Font-Regular.ttf"/>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/home_grid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:cardUseCompatPadding="true" />

            <android.support.v7.widget.CardView
                android:id="@+id/card_more_apps"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cardBackgroundColor="?attr/card_background"
                app:cardUseCompatPadding="true"
                app:cardElevation="@dimen/card_home_elevation"
                app:cardCornerRadius="@dimen/card_home_corner_radius">

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

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/home_more_apps_header"
                        android:textSize="16sp"
                        android:textColor="?android:attr/textColorPrimary"
                        android:padding="@dimen/home_content_padding"
                        fontPath="fonts/Font-Bold.ttf"/>

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="?attr/divider_list" />

                    <com.balysv.materialripple.MaterialRippleLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:mrl_rippleAlpha="0.15"
                        app:mrl_rippleColor="?attr/card_ripple"
                        app:mrl_rippleDelayClick="true"
                        app:mrl_rippleOverlay="true"
                        app:mrl_rippleDuration="500"
                        app:mrl_rippleDimension="4dp" >

                        <LinearLayout
                            android:id="@+id/more_apps"
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical"
                            android:padding="@dimen/home_content_padding">

                            <ImageView
                                android:id="@+id/more_apps_icon"
                                android:layout_width="40dp"
                                android:layout_height="40dp" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/home_more_apps"
                                android:textSize="14sp"
                                android:layout_marginLeft="@dimen/home_content_padding"
                                android:layout_marginStart="@dimen/home_content_padding"
                                android:textColor="?android:attr/textColorSecondary"
                                fontPath="fonts/Font-Regular.ttf"/>

                        </LinearLayout>

                    </com.balysv.materialripple.MaterialRippleLayout>

                </LinearLayout>

            </android.support.v7.widget.CardView>

        </LinearLayout>

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

<View
    android:id="@+id/shadow"
    android:layout_width="match_parent"
    android:layout_height="@dimen/toolbar_shadow"
    android:background="@drawable/toolbar_shadow" /></FrameLayout>

我面临的问题是当应用程序首次启动时,第一个卡片视图隐藏在 recyclerview 后面。查看此视频以了解确切的问题Issue Video

我尝试将父 LinearLayout 更改为 RelativeLayout,然后使用 layout_below 属性,但没有奏效。 知道可能是什么问题吗?另外,我是代码的初学者,所以如果我错过了一些愚蠢的事情,请放轻松。 谢谢

【问题讨论】:

  • 我只能假设RecyclerView的一部分隐藏在AppBarLayout后面,它应该出现在xml中。如果是这样,请尝试将app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到FrameLayout

标签: android layout android-recyclerview android-nestedscrollview


【解决方案1】:

终于找到了解决办法,唯一需要做的就是将recyclerview设置为像RecyclerView.setFoucsable(false)一样不可聚焦;

这是Link的原始答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多