Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在折叠工具栏布局下添加viewpager和TableLayout_Android_Android Viewpager_Android Tablayout_Android Collapsingtoolbarlayout - Fatal编程技术网

Android 如何在折叠工具栏布局下添加viewpager和TableLayout

Android 如何在折叠工具栏布局下添加viewpager和TableLayout,android,android-viewpager,android-tablayout,android-collapsingtoolbarlayout,Android,Android Viewpager,Android Tablayout,Android Collapsingtoolbarlayout,我在stackoverflow中尝试了这个问题的所有解决方案,但没有得到任何帮助。 首先,我想实现这样或类似的布局: 根据stackoverflow中的一些问题 我能够实现以下布局: 使用此xml文件: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro

我在
stackoverflow
中尝试了这个问题的所有解决方案,但没有得到任何帮助。 首先,我想实现这样或类似的布局:

根据
stackoverflow
中的一些问题 我能够实现以下布局:

使用此xml文件:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/MyAppbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/bgheader"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/aks"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/MyToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark"
                app:layout_collapseMode="pin" />

            <com.majid.whiteboard.utils.CustomTabLayout
                android:id="@+id/tab_layout_detail_activity"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                app:paddingEnd="20dp"
                app:paddingStart="20dp"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/silver"
                app:tabIndicatorHeight="4dp"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/grid_text_color"
                app:tabTextColor="@color/grid_text_color" />

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

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

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

一切正常,但现在我有两个问题:

1.Tablayout将显示在屏幕顶部,但我想将其添加到折叠工具栏下


2.我只能在折叠区域折叠工具栏(仅在pic和其顶部),而它在屏幕上的其他位置不起作用。我修改了您的代码。。。试试这个

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/MyAppbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:minHeight="@dimen/hundred_dp"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/bgheader"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/aks"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/MyToolbar"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:layout_below="@+id/dashboard_txt_des"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginTop="@dimen/fifteen_dp"
                app:titleTextAppearance="@style/Toolbar.TitleText" />


            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_below="@+id/toolbar"
                android:layout_gravity="bottom"
                android:background="@color/colorPrimary"
                app:tabIndicatorColor="@color/orange" />

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

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

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

以下是我在应用程序中如何使用
查看页面
表格布局
实现sticky
工具栏
永久

<LinearLayout 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:background="@color/background2"
    android:orientation="vertical">

    <include
        android:id="@id/toolbar"
        layout="@layout/toolbar" />

    <android.support.design.widget.CoordinatorLayout 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:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/background2"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/actionModeSplitBackground"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/plain_rectangle"
                        android:orientation="vertical">

                        <RelativeLayout
                            android:id="@+id/profile_header"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/half_padding">

                            <com.COMPANY.APP.app.custom.RoundedNetworkImageView
                                android:id="@+id/user_dp"
                                android:layout_width="@dimen/follow_logo"
                                android:layout_height="@dimen/follow_logo"
                                android:layout_centerHorizontal="true"
                                app:default_image_resource="@drawable/new_user_display" />

                            <ImageView
                                android:id="@+id/btn_edit"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentRight="true"
                                android:layout_alignParentTop="true"
                                android:padding="@dimen/more_padding"
                                android:src="@drawable/black_edit_icon" />
                        </RelativeLayout>

                        <com.COMPANY.APP.app.custom.FontTextView
                            android:id="@+id/lbl_user"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:paddingBottom="@dimen/standard_padding"
                            android:paddingTop="@dimen/standard_padding"
                            android:text="-"
                            android:textColor="@color/toolbar"
                            android:textSize="@dimen/user_name_font"
                            app:customFont="@string/font_regular" />

                        <com.COMPANY.APP.app.custom.FontTextView
                            android:id="@+id/lbl_desc"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/more_padding"
                            android:layout_marginRight="@dimen/more_padding"
                            android:paddingBottom="@dimen/standard_padding"
                            android:paddingTop="@dimen/standard_padding"
                            android:text="-"
                            android:textSize="@dimen/user_description_font"
                            app:customFont="@string/font_regular" />

                        <com.COMPANY.APP.app.custom.CustomCheckbox
                            android:id="@+id/chk_following"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginBottom="@dimen/followin_button_padding"
                            android:layout_marginTop="@dimen/standard_padding"
                            android:background="@drawable/rectangle_green_selector"
                            android:button="@null"
                            android:checked="false"
                            android:drawableLeft="@drawable/follow_green_inner_selector"
                            android:drawablePadding="10dp"
                            android:gravity="center"
                            android:paddingLeft="@dimen/follow_button_padding"
                            android:paddingRight="@dimen/follow_button_padding"
                            android:text="Follow"
                            android:textColor="@drawable/green_color_selector"
                            android:textSize="@dimen/following_button_font"
                            app:customFont="@string/font_regular" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="50dp"
                        android:layout_marginBottom="2dp"
                        android:orientation="horizontal"
                        android:paddingTop="2dp"
                        android:weightSum="3">

                        <RelativeLayout
                            android:id="@+id/wishlist_layout"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_marginRight="1dp"
                            android:layout_weight="1"
                            android:background="@color/background">

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

                                <com.COMPANY.APP.app.custom.FontTextView
                                    android:id="@+id/lbl_wishlist_count"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:gravity="center_horizontal"
                                    android:text="-"
                                    android:textColor="@color/toolbar"
                                    android:textSize="@dimen/font_14" />

                                <com.COMPANY.APP.app.custom.FontTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:gravity="center_horizontal"
                                    android:text="Wishlist"
                                    android:textColor="@color/toolbar"
                                    android:textSize="@dimen/font_10" />
                            </LinearLayout>

                            <View
                                android:layout_width="match_parent"
                                android:layout_height="4dp"
                                android:layout_alignParentBottom="true"
                                android:background="@color/button" />
                        </RelativeLayout>

                        <LinearLayout
                            android:id="@+id/following_layout"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_marginRight="1dp"
                            android:layout_weight="1"
                            android:background="@color/background"
                            android:gravity="center_vertical"
                            android:orientation="vertical">

                            <com.COMPANY.APP.app.custom.FontTextView
                                android:id="@+id/lbl_following_count"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_horizontal"
                                android:text="-"
                                android:textColor="@color/toolbar"
                                android:textSize="@dimen/font_14" />

                            <com.COMPANY.APP.app.custom.FontTextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_horizontal"
                                android:text="Following"
                                android:textColor="@color/toolbar"
                                android:textSize="@dimen/font_10" />

                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/follower_layout"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_marginRight="1dp"
                            android:layout_weight="1"
                            android:background="@color/background"
                            android:gravity="center_vertical"
                            android:orientation="vertical">

                            <com.COMPANY.APP.app.custom.FontTextView
                                android:id="@+id/lbl_follower_count"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="1dp"
                                android:layout_marginRight="1dp"
                                android:gravity="center_horizontal"
                                android:text="-"
                                android:textColor="@color/toolbar"
                                android:textSize="@dimen/font_14" />

                            <com.COMPANY.APP.app.custom.FontTextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_horizontal"
                                android:text="Followers"
                                android:textColor="@color/toolbar"
                                android:textSize="@dimen/font_10" />
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar2"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:title="Collapsing Toolbar"
                    app:layout_collapseMode="pin">

                    <com.COMPANY.APP.app.custom.RoundedNetworkImageView
                        android:id="@+id/img_profile_top"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center_vertical|left"
                        android:layout_marginRight="20dp"
                        android:alpha="0"
                        app:default_image_resource="@drawable/new_user_display" />

                    <com.COMPANY.APP.app.custom.ImageCheckbox
                        android:id="@+id/user_follow_top"
                        android:layout_width="45dp"
                        android:layout_height="30dp"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center_vertical|right"
                        android:layout_marginRight="20dp"
                        android:alpha="0"
                        android:src="@drawable/follow_icon_checkbox_drawable" />
                </android.support.v7.widget.Toolbar>

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/standard_height"
                android:layout_alignParentTop="true"
                android:background="@drawable/plain_rectangle"
                android:elevation="2dp"
                app:tabBackground="@color/background"
                app:tabIndicatorColor="@color/button"
                app:tabIndicatorHeight="3dp"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/toolbar"
                app:tabTextAppearance="@style/APPTabText"
                app:tabTextColor="@color/disable_text" />

            <com.COMPANY.APP.app.custom.CustomViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tab_layout" />
        </RelativeLayout>

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

</LinearLayout>
这是输出-

不滚动

滚动后

我也有同样的问题。我希望它对你们有用。我可以知道,你们为什么用图书馆来制作表格@majid@GovindaP我试试你的解决方案:但我有个问题,它在浏览页面上不起作用。谢谢@parama。但是你的解决方案有一个很小的问题。首先,它在viewpager区域不工作viewpager有什么问题?你能解释一下吗?@Majid我的问题是当我在“查看”寻呼机中向下或向上滑动时。折叠工具栏布局不工作。我应该在折叠工具栏区域上下滑动。它和工具栏重叠吗?问题在于工具栏/AppBar布局/折叠工具栏布局的高度。
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing_toolbar);
ImageCheckbox user_follow_top = (ImageCheckbox)findViewById(R.id.user_follow_top);
RoundedNetworkImageView imgProfile = (RoundedNetworkImageView) findViewById(R.id.user_dp);
RoundedNetworkImageView getImgProfileTop = (RoundedNetworkImageView)findViewById(R.id.img_profile_top);

AppBarLayout.OnOffsetChangedListener mListener = new AppBarLayout.OnOffsetChangedListener() {
                        @Override
                        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                            if(collapsingToolbarLayout.getHeight() + verticalOffset < 1.5 * ViewCompat.getMinimumHeight(collapsingToolbarLayout)) {
                                getImgProfileTop.animate().alpha(1).setDuration(400);
                                user_follow_top.animate().alpha(1).setDuration(400);
                                collapsingToolbarLayout.setTitle(username);
                            } else {
                                getImgProfileTop.animate().alpha(0).setDuration(400);
                                user_follow_top.animate().alpha(0).setDuration(400);
                                collapsingToolbarLayout.setTitle("");
                            }
                        }
                    };
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(mListener);