Как добавить скольжение и более быструю прокрутку в ScrollView?

Я использую ScrollView в макете фрагмента, но прокрутка происходит намного медленнее, чем в большинстве других приложений, и она вообще не скользит.

<?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 = "wrap_content"
    android:orientation = "vertical">

    <include layout = "@layout/toolbar" />

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

            <include layout = "@layout/content" />

    </ScrollView>
</RelativeLayout>

И @layout/content:

<?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">

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

    <android.support.v7.widget.RecyclerView
        android:id = "@+id/recycler_view"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:clipToPadding = "false"
        android:scrollbars = "vertical" />

      <LinearLayout 
       android:layout_width = "match_parent"
       android:layout_height = "wrap_content"
       android:layout_gravity = "center_horizontal">

        <android.support.v7.widget.CardView 
             xmlns:android = "http://schemas.android.com/apk/res/android"
             xmlns:cardview = "http://schemas.android.com/apk/res-auto"
             android:layout_width = "match_parent"
             android:layout_height = "wrap_content"
             android:layout_margin = "8dp"
             android:foreground = "?android:attr/selectableItemBackground"
             cardview:cardCornerRadius = "8dp"
             android:clickable = "true"
             android:focusable = "true">

             <LinearLayout
              android:layout_width = "fill_parent"
              android:layout_height = "wrap_content"
              android:orientation = "horizontal"
              android:padding = "6dp">

                   <ImageView
                    android:layout_width = "wrap_content"
                    android:layout_height = "wrap_content"
                    android:src = "@drawable/ic_arrow_forward_24dp" />

                    <LinearLayout
                     android:layout_width = "fill_parent"
                     android:layout_height = "wrap_content"
                     android:layout_marginStart = "4dp"
                     android:layout_weight = "0.9"
                     android:orientation = "vertical"
                     android:padding = "4dp">

                         <TextView
                          android:id = "@+id/view_more"
                          android:layout_width = "match_parent"
                          android:layout_height = "wrap_content"
                          android:text = "View more" />
                     </LinearLayout>
                 </LinearLayout>
            </android.support.v7.widget.CardView>
      </LinearLayout>
</LinearLayout>

Поделитесь пожалуйста своим макетом content.

Reaz Murshed 08.04.2018 21:36

Я добавил макет контента

Susan T. Erickson 08.04.2018 21:52
0
2
533
1

Ответы 1

Я бы посоветовал вам использовать NestedScrollView в вашем случае, поскольку у вас есть RecyclerView внутри вашего ScrollView. Измените родительский макет следующим образом.

<?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 = "wrap_content"
    android:orientation = "vertical">

    <include layout = "@layout/toolbar" />

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

            <include layout = "@layout/content" />

    </NestedScrollView>
</RelativeLayout>

у него есть v7 API, поменять его на NestedScrollView

user9025311 17.04.2018 20:04

Другие вопросы по теме