Проблема с ScrollView внутри FrameLayout - PullRequest
0 голосов
/ 20 декабря 2018

Я искал в Интернете эту проблему и не смог найти решение.

У меня есть 4 вкладки в моем макете main_activity, и в каждой вкладке я отображаю некоторую информацию, у меня есть макет кадра и Insideесть ScrollView, проблема в том, что прокрутка не происходит полностью, при прокрутке остается некоторая информация.

Проверьте нижнюю часть изображения, прокрутка остановлена.

Прокрутка остановлена ​​

Вот мой макет main_activity.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tabanim_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabanim_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="30dp"
        android:background="@color/colorPrimary"
        app:srcCompat="@drawable/ic_action_toggle_star" />

    <android.support.v4.view.ViewPager
        android:id="@+id/tabanim_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

Вот мой XML-файл макета.

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/material_grey"
    android:orientation="vertical"
    android:padding="@dimen/frame_layout_padding">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

        <android.support.v7.widget.CardView
            android:id="@+id/cardTreble"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground"
            app:cardElevation="2dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:id="@+id/cardTreble_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/cardTreble_header"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding">

                    <ImageView
                        android:id="@+id/trebleResult_image"
                        android:layout_width="@dimen/card_icon_size"
                        android:layout_height="@dimen/card_icon_size"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="16dp"
                        app:srcCompat="@drawable/circle" />

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

                        <TextView
                            style="@style/TextAppearance.AppCompat.Title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/title_treble_check"
                            android:textSize="@dimen/card_header_textsize" />

                        <TextView
                            android:id="@+id/trebleResult_title"
                            style="@style/TextAppearance.AppCompat.Subhead"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/result_pending"
                            android:textSize="@dimen/card_header_textsize" />
                    </LinearLayout>
                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/divider" />

                <TextView
                    android:id="@+id/trebleResult_desc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/padding"
                    android:text="@string/result_pending" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardSeamless"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground"
            app:cardElevation="2dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:id="@+id/cardSeamless_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/cardSeamless_header"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding">

                    <ImageView
                        android:id="@+id/seamlessResult_image"
                        android:layout_width="@dimen/card_icon_size"
                        android:layout_height="@dimen/card_icon_size"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="16dp"
                        app:srcCompat="@drawable/circle" />

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

                        <TextView
                            style="@style/TextAppearance.AppCompat.Title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/seamless_title"
                            android:textSize="@dimen/card_header_textsize" />

                        <TextView
                            android:id="@+id/seamlessResult_title"
                            style="@style/TextAppearance.AppCompat.Subhead"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/result_pending"
                            android:textSize="@dimen/card_header_textsize" />
                    </LinearLayout>
                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/divider" />

                <TextView
                    android:id="@+id/seamlessResult_desc"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/padding"
                    android:text="@string/result_pending" />

                <Button
                    android:id="@+id/seamlessResult_more"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/button_margin"
                    android:text="@string/card_learnmore" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardTrebleInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:foreground="?android:attr/selectableItemBackground"
            app:cardElevation="2dp"
            app:cardUseCompatPadding="true">

            <LinearLayout
                android:id="@+id/cardTrebleInfo_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/cardTrebleInfo_header"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding">

                    <ImageView
                        android:layout_width="@dimen/card_icon_size"
                        android:layout_height="@dimen/card_icon_size"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="16dp"
                        android:src="@drawable/ic_treble" />

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

                        <TextView
                            style="@style/TextAppearance.AppCompat.Title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/treble_info_title"
                            android:textSize="@dimen/card_header_textsize" />

                        <TextView
                            style="@style/TextAppearance.AppCompat.Subhead"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/treble_info_subhead"
                            android:textSize="@dimen/card_header_textsize" />
                    </LinearLayout>
                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/divider" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:src="@drawable/treble_banner_before" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/padding"
                    android:text="@string/treble_info_1" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:src="@drawable/treble_banner_after" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/padding"
                    android:text="@string/treble_info_2" />

                <Button
                    android:id="@+id/trebleInfo_more"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/button_margin"
                    android:text="@string/card_learnmore" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>
    </ScrollView>
</FrameLayout>

1 Ответ

0 голосов
/ 20 декабря 2018

используйте ниже в ScrollView

android:fillViewport="true"

и установите его высоту как match_parent

, потому что для прокрутки ScrollView должна быть указана высота, после которой начнется прокрутка.

ОБНОВЛЕНИЕ

использовать customscrollview, как показано ниже:

public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;

public CustomScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mGestureDetector = new GestureDetector(context, new YScrollDetector());
    setFadingEdgeLength(0);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}

// Return false if we're scrolling in the x direction  
class YScrollDetector extends SimpleOnGestureListener {
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {             
        return Math.abs(distanceY) > Math.abs(distanceX);
    }
}
}

ОБНОВЛЕНИЕ2

использовать android.support.v4.widget.NestedScrollView вместо ScrollView

...