使用能够在里面滚动的视图持有者的RecycleView

时间:2017-05-03 06:52:01

标签: android android-layout android-recyclerview

我有container.xml

 <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:id="@+id/techScrolView"


        >

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



            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="15dp"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"
                android:layout_marginLeft="30dp">


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


                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="15dp">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/profileDisplayImg"
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginTop="10dp"
                            android:background="@drawable/circle"
                            android:gravity="center"
                            android:text="@string/hint_image"
                            android:textSize="@dimen/hint_size"
                            />

                    </RelativeLayout>

                </FrameLayout>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:text="@string/edit_detail"
                    android:textColor="@color/white"
                    android:drawableLeft="@drawable/pencil"
                    android:id="@+id/edit_profile"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center"
                android:id="@+id/profileName"
                android:textColor="@color/white"
                android:textSize="@dimen/profile_text_size"
                android:padding="2dp"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center_horizontal"
                android:id="@+id/profilePlace"
                android:padding="2dp"
                android:textColor="@color/white"
                android:textSize="@dimen/profile_text_size"
                android:drawableRight="@drawable/map_marker_white"
                />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:background="@color/white"
                android:layout_marginRight="20dp"
                android:layout_marginLeft="20dp"
                android:padding="6dp"
                android:layout_marginTop="10dp"
                android:baselineAligned="false"
                android:layoutDirection="rtl"
                >

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/social_media_circle"
                    android:layout_marginRight="30dp"
                    android:layout_marginLeft="30dp"
                    >
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/google_plus"
                        android:id="@+id/profileGoogle"
                        android:layout_marginRight="5dp"
                        android:layout_centerVertical="true"
                        />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/social_media_circle"
                    android:layout_marginRight="30dp"
                    android:layout_marginLeft="30dp"
                    >
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/facebook"
                        android:id="@+id/profileFace"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="5dp"
                        />
                </RelativeLayout>



                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/social_media_circle"
                    android:layout_marginRight="30dp"
                    android:layout_marginLeft="30dp"
                    android:layout_gravity="left"

                    >
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/white_phone"
                        android:id="@+id/profileCall"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="5dp"

                        />
                </RelativeLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="40dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="15dp"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/career"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/text_display_color"
                        android:textSize="@dimen/profile_info_text_size"
                        android:text=""
                        android:padding="3dp"
                        android:layout_gravity="center|left"
                        android:gravity="left"
                        android:layout_marginRight="80dp"
                        android:id="@+id/profileSkills"
                        />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/years_experince"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/text_display_color"
                        android:layout_gravity="center"
                        android:gravity="left"
                        android:layout_marginRight="18dp"
                        android:textSize="@dimen/profile_info_text_size"
                        android:text=""
                        android:padding="5dp"
                        android:id="@+id/profileExperince"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/current_salary"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/text_display_color"
                        android:layout_gravity="center"
                        android:gravity="left"
                        android:layout_marginRight="48dp"
                        android:textSize="@dimen/profile_info_text_size"
                        android:text=""
                        android:padding="5dp"
                        android:id="@+id/profileSalary"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/kafeel_type"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/text_display_color"
                        android:layout_gravity="center"
                        android:gravity="left"
                        android:layout_marginRight="45dp"
                        android:textSize="@dimen/profile_info_text_size"
                        android:text=""
                        android:padding="5dp"
                        android:id="@+id/profileKafeel"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/nationalty"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />

                    <TextView
                        android:id="@+id/profileNationalty"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginRight="78dp"
                        android:textColor="@color/text_display_color"
                        android:gravity="left"
                        android:padding="5dp"
                        android:text=""
                        android:textSize="@dimen/profile_info_text_size" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/statuse"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />

                    <TextView
                        android:id="@+id/profileStatue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginRight="90dp"
                        android:gravity="left"
                        android:padding="5dp"
                        android:text=""
                        android:textColor="@color/text_display_color"
                        android:textSize="@dimen/profile_info_text_size" />
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/drive"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />

                    <TextView
                        android:id="@+id/profileDriveStatue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginRight="45dp"
                        android:gravity="left"
                        android:padding="5dp"
                        android:text=""
                        android:textColor="@color/text_display_color"
                        android:textSize="@dimen/profile_info_text_size" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layoutDirection="rtl"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/age"
                        android:textColor="@color/white"
                        android:textSize="@dimen/profile_text_size"
                        android:layout_gravity="center"
                        android:gravity="right"

                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/text_display_color"
                        android:layout_gravity="center"
                        android:gravity="left"
                        android:layout_marginRight="96dp"
                        android:textSize="@dimen/profile_info_text_size"
                        android:text=""
                        android:padding="5dp"
                        android:id="@+id/profileAge"/>
                </LinearLayout>


            </LinearLayout>

        </LinearLayout>

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

我将它显示在我的recycleView:

`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:paddingBottom="28dp" />
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>`

我依赖于viewHolder显示了此内容,并且它已经工作fine

但我无法在recycleView ..

内滚动

我怎么能在里面滚动?

是可能吗?

1 个答案:

答案 0 :(得分:0)

如果从NestedScrollView删除container.xml无效,可以将其添加到recyclerView layout,如果我想在recyclerView内滚动,这是我的项目:

<android.support.v4.widget.NestedScrollView
    android:layout_marginTop="20dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/lineChartDiastolic"
            android:layout_width="match_parent"
            android:layout_height="250dp"></com.github.mikephil.charting.charts.LineChart>

        <TextView
            android:id="@+id/lineChartSystolicTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/systolic"
            android:textColor="@android:color/black"
            android:textSize="20dp" />

        <com.github.mikephil.charting.charts.LineChart
            android:id="@+id/lineChartSystolic"
            android:layout_width="match_parent"
            android:layout_height="250dp"></com.github.mikephil.charting.charts.LineChart>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerForDataReportBloodPressure"
            android:layout_width="match_parent"
            android:layout_height="350dp"></android.support.v7.widget.RecyclerView>


    </LinearLayout>

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

在您的情况下,删除container.xml上的NestedScrollView,将其添加到recyclerView布局:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

    <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:scrollbarStyle="outsideOverlay"
                android:paddingBottom="28dp" />
        </android.support.v4.widget.SwipeRefreshLayout>

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

</LinearLayout>