带有cardview的scrollview和recyleview无法正常工作

时间:2018-03-23 03:29:51

标签: java android android-cardview android-scrollview

我的布局结构如下 enter image description here 我需要整个视图的滚动条,但内容隐藏在卡片视图中,不会出现滚动条。当回收视图上面的内容很大时,回收视图根本无法查看。

我很困惑问题的根源是什么。我甚至尝试过nestscrollview但仍然不是滚动条......

是因为滚动视图里面有一个recyle-view?

任何人都可以帮忙。

  <?xml version="1.0" encoding="utf-8"?>
        <ScrollView
        android:fillViewport="true"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/activity_test"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/main_back">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/my_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                android:elevation="4dp"
                android:theme="@style/ToolbarColoredBackArrow"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:weightSum="3"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <LinearLayout
                        android:gravity="center"
                        android:background="@drawable/background_login"
                        android:layout_weight="2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </LinearLayout>
                    <LinearLayout
                        android:layout_weight="1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.CardView
                        app:cardElevation="15dp"
                        app:cardCornerRadius="20dp"
                        android:layout_margin="@dimen/margin"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:padding="@dimen/padding">

                        <RelativeLayout
                            android:id="@+id/xRlQuenstionLayout"
                            android:layout_margin="@dimen/dictionary_item"
                            android:orientation="vertical"
                            android:visibility="gone"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">


                            <LinearLayout
                                android:id="@+id/xLl1"
                                android:orientation="vertical"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <TextView
                                    android:layout_alignParentRight="true"
                                    android:gravity="right"
                                    android:textStyle="bold"
                                    android:visibility="gone"
                                    android:text="00:00:10"
                                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                                    android:id="@+id/xTvTimer"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"/>




                                <TextView
                                    android:id="@+id/countDown1"
                                    android:textStyle="bold"
                                    android:layout_width="match_parent"
                                    android:gravity="left"
                                    android:layout_height="wrap_content"
                                    android:textColor="@color/gray_black_color"
                                    android:visibility="invisible" />

                                <Chronometer
                                    android:textStyle="bold"
                                    android:layout_width="match_parent"
                                    android:gravity="right"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/chrono"
                                    android:visibility="visible"/>

                                <TextView
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/xTvTitle"
                                    android:text="@string/title"
                                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                                    android:gravity="center"
                                    android:textColor="@android:color/black"/>

                                <TextView
                                    android:layout_marginTop="@dimen/dictionary_item"
                                    android:id="@+id/xTvContaint"
                                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:text="@string/title"
                                    android:gravity="center"/>

                                <LinearLayout
                                    android:layout_marginTop="@dimen/dictionary_item"
                                    android:id="@+id/xllAudioPlayer"
                                    android:orientation="vertical"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content">
                                    <include layout="@layout/media_player"
                                        android:id="@+id/media_player"
                                        android:visibility="visible"/>
                                </LinearLayout>

                                <TextView
                                    android:layout_marginTop="@dimen/dictionary_item"
                                    android:id="@+id/xTvGroup"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:visibility="visible"
                                    android:text="@string/title"
                                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                                    android:gravity="center"
                                    android:textColor="@android:color/black"/>

                                <ImageView
                                    android:layout_marginTop="@dimen/dictionary_item"
                                    android:layout_gravity="center"
                                    android:id="@+id/xImgQusImage"
                                    android:layout_width="@dimen/wordimagewidth"
                                    android:layout_height="@dimen/wordimageheight"
                                    android:src="@drawable/main_logo">
                                </ImageView>


                            </LinearLayout>

                            <LinearLayout
                                android:layout_alignParentBottom="true"
                                android:id="@+id/xLlNextLayout"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">

                                <LinearLayout
                                    android:id="@+id/xLlNextQuestion"
                                    android:layout_margin="@dimen/dictionary_item"
                                    android:layout_weight="1"
                                    android:visibility="visible"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal"
                                    android:background="@drawable/btn_background">

                                    <TextView
                                        android:padding="@dimen/padding"
                                        android:id="@+id/next_button"
                                        android:layout_width="0dp"
                                        android:layout_weight="1"
                                        android:layout_height="match_parent"
                                        android:text="Next"
                                        android:textColor="@color/white"
                                        android:textSize="@dimen/button_text_size"
                                        android:gravity="center"/>

                                    <ImageView
                                        android:id="@+id/xImgNext"
                                        android:padding="@dimen/padding"
                                        android:visibility="visible"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:src="@drawable/next"
                                        android:layout_marginRight="@dimen/margin"/>

                                </LinearLayout>

                                <LinearLayout
                                    android:id="@+id/GroupQuestionNext"
                                    android:layout_margin="@dimen/dictionary_item"
                                    android:layout_weight="1"
                                    android:layout_alignParentBottom="true"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal"
                                    android:visibility="gone"
                                    android:background="@drawable/btn_background">

                                    <TextView
                                        android:padding="@dimen/padding"
                                        android:id="@+id/next_button1"
                                        android:layout_width="0dp"
                                        android:layout_weight="1"
                                        android:layout_height="match_parent"
                                        android:text="Next"
                                        android:textColor="@color/white"
                                        android:textSize="@dimen/button_text_size"
                                        android:gravity="center"/>

                                    <ImageView
                                        android:id="@+id/xImgNext1"
                                        android:padding="@dimen/padding"
                                        android:visibility="visible"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:src="@drawable/next"
                                        android:layout_marginRight="@dimen/margin"/>
                                </LinearLayout>

                            </LinearLayout>

                            <android.support.v7.widget.RecyclerView
                                android:layout_above="@id/xLlNextLayout"
                                android:layout_below="@id/xLl1"
                                android:layout_margin="@dimen/dictionary_item"
                                android:id="@+id/xRvOptions"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                            </android.support.v7.widget.RecyclerView>


                            <LinearLayout
                                android:id="@+id/xLlFinishTest"
                                android:layout_margin="@dimen/dictionary_item"
                                android:layout_weight="1"
                                android:layout_alignParentBottom="true"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:visibility="gone"
                                android:orientation="horizontal"
                                android:background="@drawable/background_login">

                                <TextView
                                    android:padding="@dimen/padding"
                                    android:id="@+id/xTvFinish"
                                    android:layout_width="0dp"
                                    android:layout_weight="1"
                                    android:layout_height="match_parent"
                                    android:text="Finish"
                                    android:textColor="@color/white"
                                    android:textSize="@dimen/button_text_size"
                                    android:gravity="center"/>

                            </LinearLayout>

                        </RelativeLayout>

                        <LinearLayout
                            android:layout_marginTop="@dimen/cardmargintop"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/result_layout"
                            android:gravity="center"
                            android:visibility="gone">
                            <include layout="@layout/test_result"/>
                        </LinearLayout>

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

                </LinearLayout>

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

2 个答案:

答案 0 :(得分:0)

recyclerview.setNestedScrollingEnabled(false);

之后添加此行setLayoutManager

答案 1 :(得分:0)

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:padding="10dp"
    android:orientation="horizontal"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="0dp">

    <android.support.v7.widget.CardView
        android:layout_width="250dp"
        android:layout_height="145dp"
        android:layout_gravity="center"
        android:background="@drawable/one"
        app:cardCornerRadius="7dp"
        app:cardElevation="12dp">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/simple_two"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Favorites"
            android:textSize="25sp"
            android:textColor="#FFFF"
            android:padding="15sp"/>

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="15dp"
            android:text="Total  __ Songs"
            android:textColor="#FFFF"
            android:textSize="18sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:paddingBottom="10dp"
            android:layout_marginLeft="15dp"
            android:text="Play All Songs"
            android:textColor="#FFFF"
            android:textSize="18sp" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_action_button"
            android:layout_width="58dp"
            android:layout_height="58dp"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/play"
            app:backgroundTint="@android:color/transparent"
            app:borderWidth="0dp" />
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="250dp"
        android:layout_marginLeft="25dp"
        android:layout_height="145dp"
        android:layout_gravity="center"
        app:cardCornerRadius="7dp"
        app:cardElevation="12dp"
        android:background="@drawable/simple_two">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/one"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Collection"
            android:textSize="25sp"
            android:textColor="#FFFF"
            android:padding="15sp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="15dp"
            android:text="Total  __ Songs"
            android:textColor="#FFFF"
            android:textSize="18sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:paddingBottom="10dp"
            android:layout_marginLeft="15dp"
            android:text="Play All Songs"
            android:textColor="#FFFF"
            android:textSize="18sp" />

        <android.support.design.widget.FloatingActionButton
            android:layout_width="58dp"
            android:layout_height="58dp"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/play"
            app:backgroundTint="@android:color/transparent"
            app:borderWidth="0dp" />

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

    </LinearLayout>
</HorizontalScrollView>

使用它可能会有所帮助。 请不要只是复制此代码请理解并运行。