【问题标题】:Space between the View pager and tabLayout which is inside collpasing toolbarViewpager 和 tabLayout 之间的空间,位于折叠工具栏内
【发布时间】:2018-06-04 12:21:21
【问题描述】:

tab Layout 后面会显示一些空白区域。我在应用栏布局之外有视图寻呼机,在折叠工具栏内的相对布局内有标签布局。无法确定从何处添加此额外空间。任何帮助,将不胜感激。视图的层次结构是 Coordinator、App Bar、Collapsing Toolbar、Frame Layout、Relative Layout、Tab Layout。 下面是代码

<?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"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_bg"
android:fitsSystemWindows="true"
android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="500dp"
    android:background="?attr/colorPrimary">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:titleEnabled="false">


        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_collapseMode="parallax">


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

                <LinearLayout
                    android:id="@+id/header_picture"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_weight="1"
                    android:background="@drawable/splash"
                    android:orientation="horizontal"
                    android:visibility="visible" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1">

                    <TextView
                        android:id="@+id/tv_profile_name"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="60dp"
                        android:text="Kunal Bagla"
                        android:textColor="@android:color/black"
                        android:textSize="19dp" />

                    <TextView
                        android:id="@+id/tv_profile_location"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/tv_profile_name"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="10dp"
                        android:text="Udaipur"
                        android:textColor="@android:color/black"
                        android:textSize="15dp" />

                    <TextView
                        android:id="@+id/tv_settings"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="20dp"
                        android:layout_marginTop="10dp"
                        android:background="@drawable/black_border_rounded"
                        android:gravity="right"
                        android:paddingBottom="10dp"
                        android:paddingLeft="15dp"
                        android:paddingRight="15dp"
                        android:paddingTop="10dp"
                        android:text="Settings"
                        android:textColor="@android:color/black"
                        android:textSize="15dp"
                        android:visibility="visible" />

                    <android.support.design.widget.TabLayout
                        android:id="@+id/tablayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tv_profile_location"
                        android:layout_marginTop="10dp"
                        app:tabIndicatorColor="@color/orange"
                       />


                </RelativeLayout>
            </LinearLayout>

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/drawee_avatar"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center|left"
                android:layout_marginLeft="20dp"
                fresco:placeholderImage="@drawable/home_bg"
                fresco:placeholderImageScaleType="centerCrop"
                fresco:roundAsCircle="true" />

            <FrameLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center|left"
                android:layout_marginLeft="110dp">

                <TextView
                    android:id="@+id/drawee_camera"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="8dp"
                    android:text="camera"
                    android:textAlignment="center"
                    android:textColor="@color/whiteColor"
                    android:textSize="12sp" />
            </FrameLayout>
        </FrameLayout>


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

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

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/menu_icon_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:padding="5dp" />

                    <Button
                        android:id="@+id/button_app_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_centerHorizontal="true"
                        android:gravity="center_horizontal" />

                    <TextView
                        android:id="@+id/tv_login_logout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:gravity="right"
                        android:padding="5dp" />

                </RelativeLayout>

            </LinearLayout>


        </android.support.v7.widget.Toolbar>

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

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

【问题讨论】:

    标签: android android-collapsingtoolbarlayout


    【解决方案1】:
    Some empty space is shown after tab Layout.
    

    指定你的意思(选项卡布局内部还是最佳打印打印屏幕外部) 是否仅在 1 个地方有这个额外的空间或在所有 AppBarLayout 中

    你在活动中修改了那些项目?

    我会先检查那些布局的行为,然后逐个添加下一个项目,然后你可能会看到有什么问题和关于

    【讨论】:

    • 嘿,谢谢,但空间似乎是因为 appbar 布局中指定的高度。现在减少会导致顶部图像缩小。顺便感谢您对问题的回复。
    • 我将发布一个完整的解决方案,以便将来如果有人需要这种行为它可用。我从 4-5 天就开始工作了。希望有人能从中得到帮助。
    【解决方案2】:

    如果其他人需要,这里是解决方案。如果您希望固定工具栏并在使用折叠模式下滚动内容作为工具栏的 pin 和 scrollFlags 作为滚动|exitAlwaysCollapsed 用于折叠工具栏

    <?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"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey_bg"
    android:fitsSystemWindows="true"
    android:orientation="vertical">
    
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary">
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
         app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
            app:titleEnabled="false">
    
            <android.support.constraint.ConstraintLayout
                android:id="@+id/parentLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <ImageView
                    android:id="@+id/image_view_product"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:src="@drawable/splash" />
    
                <com.facebook.drawee.view.SimpleDraweeView
                    android:id="@+id/drawee_avatar"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:layout_gravity="center|left"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="100dp"
                app:layout_constraintBottom_toBottomOf="@+id/image_view_product"
                    app:layout_constraintLeft_toLeftOf="parent"
                   app:layout_constraintTop_toBottomOf="@+id/image_view_product"
                    fresco:placeholderImage="@drawable/home_bg"
                    fresco:placeholderImageScaleType="centerCrop"
                    fresco:roundAsCircle="true" />
    
                <FrameLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|left"
                    android:layout_marginLeft="110dp"
                    android:visibility="visible">
    
                    <TextView
                        android:id="@+id/drawee_camera"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="8dp"
                        android:text="camera"
                        android:textAlignment="center"
                        android:textColor="@color/whiteColor"
                        android:textSize="12sp" />
                </FrameLayout>
    
    
                <TextView
                    android:id="@+id/tv_profile_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="70dp"
                    android:text="XYZ"
                    android:textColor="@android:color/black"
                    android:textSize="19dp"
                    app:layout_constraintTop_toBottomOf="@id/image_view_product"    />
    
                <TextView
                    android:id="@+id/tv_profile_location"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tv_profile_name"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="10dp"
                    android:text="Location"
                    android:textColor="@android:color/black"
                    android:textSize="15dp"
                    app:layout_constraintTop_toBottomOf="@+id/tv_profile_name" />
    
                <TextView
                    android:id="@+id/tv_settings"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/black_border_rounded"
                    android:gravity="right"
                    android:paddingBottom="10dp"
                    android:paddingLeft="15dp"
                    android:paddingRight="15dp"
                    android:paddingTop="10dp"
                    android:text="Settings"
                    android:textColor="@android:color/black"
                    android:textSize="15dp"
                    android:visibility="visible"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/image_view_product" />
    
                <android.support.design.widget.TabLayout
                    android:id="@+id/tablayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                  app:layout_constraintTop_toBottomOf="@+id/tv_profile_location"
                    android:layout_below="@+id/tv_profile_location"
                    android:layout_marginTop="10dp"
                    app:tabIndicatorColor="@color/orange" />
    
        </android.support.constraint.ConstraintLayout>
    
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/orange"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="parallax">
    
            <LinearLayout
                android:id="@+id/ll_sub_main_dice"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <TextView
                        android:id="@+id/menu_icon_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:padding="5dp" />
    
                    <Button
                        android:id="@+id/button_app_icon"
                        android:layout_width="40dp"
                        android:layout_height="40dp"
                        android:layout_centerHorizontal="true"
                        android:gravity="center_horizontal" />
    
                    <TextView
                        android:id="@+id/tv_login_logout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:gravity="right"
                        android:padding="5dp" />
    
                </RelativeLayout>
    
            </LinearLayout>
    
    
        </android.support.v7.widget.Toolbar>
    
    </android.support.design.widget.CollapsingToolbarLayout>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多