首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android - umano SlidingUpPanelLayout -内容fitsSystemWindows

Android - umano SlidingUpPanelLayout -内容fitsSystemWindows
EN

Stack Overflow用户
提问于 2017-04-06 02:25:06
回答 2查看 908关注 0票数 0

我正在使用下面的库:https://github.com/umano/AndroidSlidingUpPanel

我想在滚动时在状态栏下面显示一些东西,但我不能使main_content (SlidingUpPanelLayout的第一个容器)适合屏幕。我想在滚动时在状态栏下面显示一些东西。

这是我的第一个xml配置:

代码语言:javascript
复制
<android.support.v4.widget.DrawerLayout 
    ...
    android:fitsSystemWindows="true">

    <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout
        ...
        android:fitsSystemWindows="true">

        <!-- This is where I don't get what I want,
             This container has always a padding top equals to the 
             status bar size, so it will always affect the direct 
             childs => main_content (my fragments container) -->
        <com.sothree.slidinguppanel.SlidingUpPanelLayout
            android:id="@+id/sliding_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true" // seems to not be supported
            android:gravity="bottom"
            ...>

            <!-- Main content - fragments placeholder -->
            <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout
                android:id="@+id/main_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true" // if the parent doesn't it will not either.
                tools:background="@color/colorAccent" />

            <!-- Panel     -->
            <FrameLayout
                android:id="@+id/..."
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:fitsSystemWindows="false" />
        </com.sothree.slidinguppanel.SlidingUpPanelLayout>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom">

            <com.hnhh.app3.widgets.BannerAdWrapper.../>
        </FrameLayout>

    </com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout>

    <include layout="@layout/navigation" />

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

我尝试了几个家长的sliding_layout,但我不能设法拥有所需的行为。sliding_layout永远不适合屏幕。

我尝试过的另一种方法是用一个空的ViewGroup替换main_content,它必须是match_paren的(库希望是这样的),main_content不是在SlidingUpPanelLayout内部,而是在它之前。

代码语言:javascript
复制
<android.support.v4.widget.DrawerLayout >
    <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout>

        <!-- NEW Main content - fragments placeholder -->
        <com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout />

        <com.sothree.slidinguppanel.SlidingUpPanelLayout>
            <!--  Replaced old main_content with empty     -->
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <!--  Panel     -->
            <FrameLayout />
        </com.sothree.slidinguppanel.SlidingUpPanelLayout>

        <FrameLayout>
            <com.hnhh.app3.widgets.BannerAdWrapper/>
        </FrameLayout>

    </com.hnhh.app3.fragments.model.FitsSystemWindowsFrameLayout>

    <include layout="@layout/navigation" />

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

第二个解决方案的问题是,我有一个空的容器,它将拦截所有的触摸事件,但我无法将它们传递给主要内容。

有谁有变通办法吗?谢谢

EN

回答 2

Stack Overflow用户

发布于 2017-04-07 01:49:12

好了,我找到了一条路。

我删除了这个库,并使用了一个像https://github.com/fedorenkoalex/bottomsheetrecycler/一样的自定义BottomSheetBehavior。点击链接,看看它是如何实现的。感谢fedorenkoalex的解决方案。

结果几乎是一样的,唯一的事情是当你滚动嵌套回收器视图(或其他滚动视图)时,它将很好地处理滚动,除非你不能再向上滚动:如果RecyclerView已经在顶部,而您试图滚动顶部,那么它将向下推动底部页面。归根结底,这不是坏事,因为这是一种直觉行为。

票数 0
EN

Stack Overflow用户

发布于 2017-04-07 02:04:40

您可以使用此xml布局:

代码语言:javascript
复制
<!-- MAIN CONTENT -->
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    tools:context="com.amitupadhyay.clickin.in.amitupadhyay.clickin.ui.MainActivity">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" >

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

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabLayout"
            app:tabMode="scrollable"
            app:tabGravity="fill"
            app:tabTextAppearance="@style/MY_TAB_STYLE">
        </android.support.design.widget.TabLayout>

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

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

        </android.support.v4.view.ViewPager>

    <include layout="@layout/content_main" />

</LinearLayout>


<!-- SLIDING LAYOUT -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:clickable="true"
    android:focusable="false"
    android:id="@+id/dragView">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="68dp"
        android:background="@color/colorPrimary"
        android:id="@+id/bottomPannerLinearLayout"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:textSize="14sp"
            android:textColor="@android:color/white"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"/>

        <Button
            android:id="@+id/follow"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:textSize="14sp"
            android:gravity="center_vertical|right"
            android:paddingRight="10dp"
            android:paddingLeft="10dp"/>

    </LinearLayout>

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

            <TextView
                android:id="@+id/anyid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"/>


            <Button
                android:layout_width="wrap_content"
                android:layout_height="55dp"
                android:id="@+id/anyotherid"
                style="@style/AppTheme.Button"
                android:layout_marginTop="20dp"
                android:layout_gravity="center_horizontal"
                android:textStyle="bold"
                android:padding="10dp"
                android:textSize="20sp"
                android:text="Submit"/>

        </LinearLayout>
    </ScrollView>

</LinearLayout>

这对我来说很有用。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43238890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档