Reputation: 205
I am using the following library : https://github.com/umano/AndroidSlidingUpPanel.
I want to display things below status bar when scrolling and I can't make the main_content (first container of the SlidingUpPanelLayout) fit the screen. I want to display things below status bar when scrolling.
This is my first xml configuration :
<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>
I tried with several parent's for the sliding_layout but I can't manage to have the desired behavior. The sliding_layout never fits the screen.
Another way I tried, which kinda works, is to replace main_content with an empty ViewGroup which has to match_paren (the library wants it that way) and the main_content not inside the SlidingUpPanelLayout but before.
<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>
The thing with the second solution is that I have an empty container that will intercept all touch events and I couldn't manage to pass them to the main content.
Does anyone got a workaround? Thanks
Upvotes: 0
Views: 995
Reputation: 7401
You can use this xml Layout:
<!-- 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>
This works great for me. :)
Upvotes: 0
Reputation: 205
Ok, so I found a way through.
I removed the library and used a custom BottomSheetBehavior like in https://github.com/fedorenkoalex/bottomsheetrecycler/. Follow the link and look how it was implemented. Thanks to fedorenkoalex for the solution.
The results are almost the same, the only thing is when you scroll the nested recycler view (or other scroll view) it will handle scrolls well except when you cannot scroll up anymore : if the RecyclerView is already at the top and you try to scroll top, then it will push the bottom sheet down. Which is not bad in the end because it's an intuitive behavior.
Upvotes: 0