Прокрутите все макет с ViewPager - PullRequest
2 голосов
/ 30 октября 2019

Мой главный экран состоит из двух линейных макетов, одним из которых является ViewPager, в который загружаются данные из RecyclerView. Вот скриншот основного экрана . Будет прокручиваться только нижняя часть самого ViewPager, и мне нужно прокрутить весь экран. Если я установил фиксированную высоту в ViewPager, например, 2000dp, то все работает, но если wrap_content, то прокручивается только viewPager. Как решить эту проблему?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

tools:context="com.example.wilshere.voicerecognitionactivity.VoiceRecognitionActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

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


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


<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/CharacterGrayLight"
android:orientation="vertical"
android:id="@+id/char_scroll"
>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:background="@drawable/gradientbackground"
        android:layout_height="350dp"
        android:orientation="vertical">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_marginTop="20dp"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/ic_person"></ImageView>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:text="Your name"
            android:textColor="#fff"
            android:textStyle="bold"
            android:textSize="21sp">
        </TextView>
    </LinearLayout>
    <android.support.v7.widget.CardView
        android:layout_width="350dp"
        android:layout_height="120dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="275dp"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="3">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_height="match_parent">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Рейтинг:"
                    android:textAlignment="center"
                    android:textSize="18sp"></TextView>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="30.5"
                    android:textStyle="bold"
                    android:textSize="20sp"
                    android:paddingTop="10dp"
                    android:textColor="@color/CharacterStartBlue"></TextView>
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_height="match_parent">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Выполнено задач:"
                    android:textAlignment="center"
                    android:textSize="18sp"></TextView>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="125"
                    android:textStyle="bold"
                    android:textSize="20sp"
                    android:paddingTop="10dp"
                    android:textColor="@color/CharacterStartBlue"></TextView>
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_height="match_parent">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Возраст:"
                    android:textAlignment="center"
                    android:textSize="18sp"></TextView>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="21"
                    android:textStyle="bold"
                    android:textSize="20sp"
                    android:paddingTop="10dp"
                    android:textColor="@color/CharacterStartBlue"></TextView>
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>
<LinearLayout
    android:id="@+id/rec_v"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="com.example.wilshere.voicerecognitionactivity.VoiceRecognitionActivity">

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/RecycleAccent"
        android:id="@+id/tablayout_char_id"
        ></android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/viewpager_char_id"></android.support.v4.view.ViewPager>



</LinearLayout>

</LinearLayout>
</ScrollView>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu_navigation"/>
</android.support.v4.widget.DrawerLayout>

Вот фрагмент из RecyclerView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/character_recyclerview">
</android.support.v7.widget.RecyclerView>
</LinearLayout>

1 Ответ

0 голосов
/ 06 ноября 2019

привет, если вы хотите прокрутить вверх до верхнего ViewPager, используйте CollapsingToolbarLayout, как в примере ниже

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipyrefreshlayout"
    app:srl_direction="top"
    >
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent">
                ​

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:contentScrim="?colorPrimary"
                    card_view:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <RelativeLayout
                        android:id="@+id/layoutcollapse"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:background="@android:color/white"
                        android:gravity="center"
                        android:orientation="vertical"
                        card_view:layout_collapseMode="parallax">

                        <ImageView
                            android:id="@+id/cover_image"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/_150dp"
                            android:scaleType="center"
                            android:src="@drawable/default_cover" />

                        <LinearLayout
                            android:id="@+id/layCenter"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:gravity="center"
                            android:orientation="vertical">


                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_60dp">

                                <de.hdodenhof.circleimageview.CircleImageView
                                    android:id="@+id/profile_image"
                                    android:layout_width="@dimen/_150dp"
                                    android:layout_height="@dimen/_120dp"
                                    android:layout_centerInParent="true"
                                    android:layout_gravity="center"
                                    android:fitsSystemWindows="true"
                                    android:padding="10dp"
                                    android:src="@drawable/sampledp"
                                    app:layout_collapseMode="parallax" />

                                <android.support.design.widget.FloatingActionButton
                                    android:id="@+id/fab_coach_artist"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_alignParentRight="true"
                                    android:layout_marginTop="@dimen/_60dp"
                                    android:layout_marginRight="@dimen/_40dp"
                                    android:backgroundTint="@color/White"
                                    android:elevation="0dp"
                                    android:visibility="gone"
                                    app:layout_collapseMode="parallax"
                                    app:srcCompat="@drawable/ic_icon_whistle" />

                                <android.support.design.widget.FloatingActionButton
                                    android:id="@+id/fab_edit"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="@dimen/_40dp"
                                    android:layout_marginTop="@dimen/_60dp"
                                    android:backgroundTint="@color/White"
                                    android:elevation="0dp"
                                    android:src="@drawable/icon_edit"
                                    android:visibility="gone"
                                    app:layout_collapseMode="parallax" />
                                ​
                            </RelativeLayout>

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/_10dp"
                                android:orientation="vertical">


                                <android.support.v7.widget.AppCompatTextView
                                    android:id="@+id/user_name"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:textColor="@color/black" />

                                <android.support.v7.widget.AppCompatTextView
                                    android:id="@+id/tv_usertype"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:textColor="@color/gray"
                                    android:textSize="@dimen/_12dp" />

                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="@dimen/_10dp"
                                    android:gravity="center"
                                    android:orientation="horizontal"
                                    android:weightSum="1">

                                    <LinearLayout
                                        android:id="@+id/linearlayout_followers"
                                        android:layout_width="0dp"
                                        android:layout_height="wrap_content"
                                        android:layout_weight=".2"
                                        android:orientation="vertical">

                                        <android.support.v7.widget.AppCompatTextView
                                            android:id="@+id/tv_followers"
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:gravity="center"
                                            android:text="0"
                                            android:textColor="@color/black"
                                            android:textSize="@dimen/_12dp" />

                                        <android.support.v7.widget.AppCompatTextView
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:fontFamily="@font/poppins_bold"
                                            android:gravity="center"
                                            android:text="Followers"
                                            android:textColor="@color/gray"
                                            android:textSize="@dimen/_12dp"
                                            android:textStyle="bold" />

                                    </LinearLayout>

                                    <LinearLayout
                                        android:id="@+id/linearlayout_followings"
                                        android:layout_width="0dp"
                                        android:layout_height="wrap_content"
                                        android:layout_weight=".2"
                                        android:orientation="vertical">

                                        <android.support.v7.widget.AppCompatTextView
                                            android:id="@+id/tv_following"
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:gravity="center"
                                            android:text="0"
                                            android:textColor="@color/black"
                                            android:textSize="@dimen/_12dp" />

                                        <android.support.v7.widget.AppCompatTextView
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:fontFamily="@font/poppins_bold"
                                            android:gravity="center"
                                            android:text="Followings"
                                            android:textColor="@color/gray"
                                            android:textSize="@dimen/_12dp"
                                            android:textStyle="bold" />

                                    </LinearLayout>

                                    <LinearLayout
                                        android:id="@+id/linearlayout_groups"
                                        android:layout_width="0dp"
                                        android:layout_height="wrap_content"
                                        android:layout_weight=".2"
                                        android:orientation="vertical">

                                        <android.support.v7.widget.AppCompatTextView
                                            android:id="@+id/tv_groups"
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:gravity="center"
                                            android:text="0"
                                            android:textColor="@color/black"
                                            android:textSize="@dimen/_12dp" />

                                        <android.support.v7.widget.AppCompatTextView
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:fontFamily="@font/poppins_bold"
                                            android:gravity="center"
                                            android:text="Groups"
                                            android:textColor="@color/gray"
                                            android:textSize="@dimen/_12dp"
                                            android:textStyle="bold" />
                                    </LinearLayout>
                                </LinearLayout>


                                <android.support.v7.widget.AppCompatButton
                                    android:id="@+id/btn_follow"
                                    android:layout_width="@dimen/_80dp"
                                    android:layout_height="@dimen/_30dp"
                                    android:layout_alignBaseline="@+id/tv_artistname"
                                    android:layout_alignParentRight="true"
                                    android:layout_gravity="center"
                                    android:layout_marginTop="@dimen/_10dp"
                                    android:background="@drawable/button_bg"
                                    android:text="Follow"
                                    android:textAllCaps="false"
                                    android:textColor="@color/White"
                                    android:textSize="@dimen/_12dp"
                                    android:textStyle="bold"
                                    android:visibility="gone" />

                                <android.support.v7.widget.AppCompatButton
                                    android:id="@+id/btn_logout"
                                    android:layout_width="@dimen/_80dp"
                                    android:layout_height="@dimen/_30dp"
                                    android:layout_alignBaseline="@+id/tv_artistname"
                                    android:layout_alignParentRight="true"
                                    android:layout_gravity="center"
                                    android:layout_marginTop="@dimen/_10dp"
                                    android:background="@drawable/button_bg"
                                    android:text="Logout"
                                    android:textAllCaps="false"
                                    android:textColor="@color/White"
                                    android:textSize="@dimen/_12dp"
                                    android:textStyle="bold"
                                    android:visibility="visible" />

                                <android.support.v7.widget.AppCompatTextView
                                    android:id="@+id/tv_description"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="@dimen/_10dp"
                                    android:layout_marginBottom="@dimen/_10dp"
                                    android:gravity="center"
                                    android:text=""
                                    android:textColor="@color/gray"
                                    android:textSize="@dimen/_12dp"
                                    android:textStyle="bold" />

                                <android.support.v7.widget.AppCompatButton
                                    android:id="@+id/btn_conversion"
                                    android:layout_width="@dimen/_130dp"
                                    android:layout_height="@dimen/_30dp"
                                    android:layout_alignBaseline="@+id/tv_artistname"
                                    android:layout_alignParentRight="true"
                                    android:layout_gravity="center"
                                    android:layout_marginBottom="@dimen/_25dp"
                                    android:background="@drawable/button_bg"
                                    android:text="View Artist Profile"
                                    android:textAllCaps="false"
                                    android:textColor="@color/White"
                                    android:textSize="@dimen/_12dp"
                                    android:textStyle="bold"
                                    android:visibility="gone" />

                            </LinearLayout>
                        </LinearLayout>
                    </RelativeLayout>
                    ​
                </android.support.design.widget.CollapsingToolbarLayout>
                ​


                <android.support.design.widget.TabLayout
                    android:id="@+id/tab_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:background="@color/light"
                    app:tabIndicatorColor="@color/app_orange2"
                    app:tabIndicatorFullWidth="false"
                    app:tabIndicatorHeight="@dimen/_3dp"
                    app:tabMode="scrollable"
                    app:tabSelectedTextColor="@color/app_orange2"
                    app:tabTextAppearance="@style/MyCustomTabText"
                    app:tabTextColor="#3D3E40" />
            </android.support.design.widget.AppBarLayout>
            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        </android.support.design.widget.CoordinatorLayout>


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