【问题标题】:Coordinator Layout cuts off screen from bottomCoordinator Layout 从底部截断屏幕
【发布时间】:2023-03-23 01:45:02
【问题描述】:

在这里,我在 CoordinatorLayout 内使用 CollapsingToolbarLayout 隐藏和显示 TabLayout,但它每次都会切开移动设备屏幕并在底部显示黑色

我正在关注此代码。但它仍然从底部获得空间,没有任何边距。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="0dp">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/id_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/tab_green"
        android:paddingBottom="0dp"
        app:elevation="0dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/mainTabLayout"
                android:layout_width="match_parent"
                android:layout_height="58dp"
                android:layout_marginBottom="0dp"
                android:clickable="false"
                app:tabBackground="@drawable/selector_tab"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/green"
                app:tabIndicatorHeight="0dp"
                app:tabMaxWidth="72dp"
                app:tabMode="scrollable"
                app:tabPaddingEnd="0dp"
                app:tabPaddingStart="0dp" />

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

        <RelativeLayout
            android:id="@+id/btn_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/transparent2">

            <View
                android:id="@+id/view_black"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/black_light"></View>

            <View
                android:id="@+id/view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/view_black"
                android:background="@color/date_color"></View>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/view"
                android:layout_centerHorizontal="true"
                android:background="@drawable/tap_icon"
                android:visibility="visible"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        </RelativeLayout>
    </android.support.design.widget.AppBarLayout>

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

        <com.cws.widget.NonSiwpablePager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

<RelativeLayout
    android:id="@+id/relative_web"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone">

    <ImageView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/home"
        android:visibility="gone"></ImageView>

    <Button
        android:id="@+id/close_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@android:color/transparent"
        android:text="@string/got_it"
        android:textColor="@color/green"
        android:textSize="@dimen/et_tSize_big"
        android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>

【问题讨论】:

    标签: android android-layout android-coordinatorlayout android-collapsingtoolbarlayout


    【解决方案1】:

    我不知道你在尝试什么,只是设置一下

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <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/tabanim_maincontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/tabanim_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
    
                <!-- View that will be hidden when video goes fullscreen -->
                <RelativeLayout
                    android:id="@+id/nonVideoLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white">
    
                    // your view
    
                </RelativeLayout>
    
    
            </RelativeLayout>
    
    
            /***
            Here You can add custom layout
            **/
    
    
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                app:tabIndicatorColor="@android:color/holo_blue_light"
                app:tabSelectedTextColor="@color/black"
                app:tabTextColor="@color/black" />
    
        </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.support.design.widget.CoordinatorLayout>
    
    
    </android.support.v4.widget.SwipeRefreshLayout>
    

    【讨论】:

    • I don't know what are you trying 这就是我发布代码的原因。
    • 哈哈哈上面的代码是你想要的,试试吧。 :D
    【解决方案2】:

    尝试这样做-

    <?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:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="0dp">
    
            <android.support.design.widget.AppBarLayout
                android:id="@+id/id_appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/tab_green"
                android:paddingBottom="0dp"
                app:elevation="0dp">
    
                <android.support.design.widget.CollapsingToolbarLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|enterAlways">
    
                    <android.support.design.widget.TabLayout
                        android:id="@+id/mainTabLayout"
                        android:layout_width="match_parent"
                        android:layout_height="58dp"
                        android:layout_marginBottom="0dp"
                        android:clickable="false"
                        app:tabBackground="@drawable/selector_tab"
                        app:tabGravity="fill"
                        app:tabIndicatorColor="@color/green"
                        app:tabIndicatorHeight="0dp"
                        app:tabMaxWidth="72dp"
                        app:tabMode="scrollable"
                        app:tabPaddingEnd="0dp"
                        app:tabPaddingStart="0dp" />
    
                </android.support.design.widget.CollapsingToolbarLayout>
    
                <RelativeLayout
                    android:id="@+id/btn_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/transparent2">
    
                    <View
                        android:id="@+id/view_black"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/black_light"></View>
    
                    <View
                        android:id="@+id/view"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_below="@+id/view_black"
                        android:background="@color/date_color"></View>
    
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/view"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/tap_icon"
                        android:visibility="visible"/>
                </RelativeLayout>
            </android.support.design.widget.AppBarLayout>
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
                <com.cws.widget.NonSiwpablePager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                     />        
        <RelativeLayout
            android:id="@+id/relative_web"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone">
            <ImageView
                android:id="@+id/web_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/home"
                android:visibility="gone"></ImageView>
    
            <Button
                android:id="@+id/close_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:background="@android:color/transparent"
                android:text="@string/got_it"
                android:textColor="@color/green"
                android:textSize="@dimen/et_tSize_big"
                android:visibility="gone" />
        </RelativeLayout>
            </RelativeLayout>
        </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

    • 我以前也做过,但我还是按照你说的再试了一次,但它没有改变任何东西。
    • 您必须将此行为设置为仅相对布局。 app:layout_behavior="@string/appbar_scrolling_view_behavior" 此行为必须在 xml 文件中出现一次。
    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多