Problem with correct display of BottomSheet - android

There was a problem with displaying bottomSheet on some devices (the case is quite rare, but it exists and interests how to remove it)
Look at the picture:
The meaning is this: there is 1 activity with .xml CoordinatorLayout, and it already contains several other markups included in it (mainly constraintLayout or LinearLayout)
They all go as bottomSheetBehaviour.
Main activity markup:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/activity_land"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:focusableInTouchMode="false"
android:isScrollContainer="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/bg_select_device" />
<include
android:id="#+id/slide_experiment"
layout="#layout/view_show_slide" />
<include
android:id="#+id/landing_"
layout="#layout/view_landing"
android:visibility="visible"
tools:visibility="visible" />
<include
android:id="#+id/confirm_decision"
android:background="#37050505"
layout="#layout/view_confirm_solution" />
<include
android:id="#+id/confirmation_getting_location"
android:background="#37050505"
layout="#layout/view_getting_location" />
<include
android:id="#+id/confirmation_app_settings"
android:background="#37050505"
layout="#layout/view_app_settings" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Interested in how to hide the "bottom" bottomSheet so that everything is displayed correctly. Thank you advance!

Related

Margin to the scrollbar only (not to recyclerview) on recyclerview

My recycler view lies under my toolbar, as you can see from the first picture. However, I have a scrollbar on the right side of it. I have to give a margin-top to this scrollbar. I have tried with giving style. And I know about clip padding with padding-top and padding-bottom, however, I need this exactly. Are there any ways to make it real?
This is my problem
The result that I want
P.S. I know that it is not the best practice. I would appreciate any help. It is one of my first questions, don't judge me so strong. :)
My main XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/background1"
android:keepScreenOn="true"
tools:context=".ui.main.HomeActivity">
<androidx.viewpager.widget.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pager" />
<include layout="#layout/toolbar_sura_detail" />
<include layout="#layout/player" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
My Fragment XML inside ViewPager
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/background1">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/kuranDetailList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:fitsSystemWindows="true"
android:scrollbarSize="2dp"
android:scrollbarThumbVertical="#drawable/thumbforrecycle"
android:scrollbars="vertical"
android:orientation="vertical" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try using this structure in your main XML and add scrolling layout behaviour for ViewPager
<androidx.coordinatorlayout.widget.CoordinatorLayout...
<com.google.android.material.appbar.AppBarLayout...
<androidx.appcompat.widget.Toolbar...
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pager"
app:layout_behavior = "com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>

Why does picture-in-picture show invisible content?

I have something very strange:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<DrawerLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frameLayoutRoot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:visibility="invisible"
android:layout_margin="10dp">
<fragment
android:id="#+id/fooFragment"
android:name="net.mydomain.android.FooFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:fitsSystemWindows="false"
app:itemBackground="#drawable/layout_background"
app:menu="#menu/activity_single_view" />
</DrawerLayout>
</layout>
Please note android:visibility="invisible" of FrameLayout. The normal screen is exactly as expected - nothing shows:
However, picture-in-picture shows the following:
It shows the content (the fragment) outside of FrameLayout that is supposed to be invisible.
Could anyone shed some light on this?
The picture-in-picture is done by following the official guideline. Nothing special.
[Edit] 2019-08-26:
I added
android:layout_margin="10dp"
to the invisible FrameLayout. The result is exactly the same. This means the gray box is the root layout.

Toolbar in the wrong location on BottomNavigationView

I'm building an app and when I load the view with the BottomNavigationView, I have odd issues all the time, sometimes, I have an extra space and other times, the toolbar is wrongly located, for example:
With bottom navigation:
Without bottom navigation:
This is my code for the 1st image:
<?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:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="#menu/toolbar_recipe" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:labelVisibilityMode="unlabeled"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color" />
</LinearLayout>
</RelativeLayout>
Toolbar:
<?xml version="1.0" encoding="UTF-8" ?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar_recipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/ToolBarStyle"
android:minHeight="?android:attr/actionBarSize"
android:background="#color/colorPrimary"/>
And this is how it behaves with the CoordinatorLayout, after I set the paddingTop as ?attr/actionBarSize the FrameLayout moved some space, but it's still wrongly located.
With CoordinatorLayout:
<?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:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_above="#+id/bottom_navigation">
<include
layout="#menu/toolbar_recipe" />
<FrameLayout
android:id="#+id/content_frame"
android:paddingTop="?attr/actionBarSize"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:labelVisibilityMode="unlabeled"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color" />
</RelativeLayout>
Without that addition, it just stays behind. I'm working in Android 8+, but I don't think it's the issue and I'm out of ideas how to coordinate that situation. Has anyone experienced it?
Thanks for any comment, especially of why it's happening since I cannot understand it.
I found the answer based on this line:
android:fitsSystemWindows="true"
I needed to add it to the root element more or less like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#android:color/white"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
And here is a description of the property:
System windows are the parts of the screen where the system is drawing
either non-interactive (in the case of the status bar) or interactive
(in the case of the navigation bar) content.
Most of the time, your app won’t need to draw under the status bar or
the navigation bar, but if you do: you need to make sure interactive
elements (like buttons) aren’t hidden underneath them. That’s what the
default behavior of the android:fitsSystemWindows="true" attribute
gives you: it sets the padding of the View to ensure the contents
don’t overlay the system windows.
I found it here:
Why would I want to fitsSystemWindows?

Move layout above bottom sheet when it opens

I want base layout which is currently a included RecyclerView move above Bottomsheet when it opens. Same like adjustResize behaviour.
I tried to set anchor but it does not seem to work.
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<LinearLayout
style="#style/llDefault"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/layout_toolbar_single_chat" />
<TextView
android:id="#+id/tvOnlineStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/space_small"
android:background="#drawable/bg_edittext_green"
android:padding="#dimen/space_small"
android:textColor="#color/white"
tools:text="Online" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include
layout="#layout/layout_recycler_view_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/peek_height_bottomsheet"
app:layout_anchor="#+id/bottomSheet"
app:layout_anchorGravity="bottom|end" />
<include
android:id="#+id/bottomSheet"
layout="#layout/layout_bottom_options_single_chat" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</layout>
I am stuck since 1 hour in this.
Try to change this app:layout_anchorGravity="bottom|end" to app:layout_anchorGravity="top"
Note:-
And to get the advantages of coordinator layout behaiour features , the views need to be direct child of the corrdinator layout.
Hope this helps.

RecyclerView is not working in NestedScrollView

I am using NestedScrollView in tab layout and when I implemented RecyclerView in NestedScrollView 2 problems occur:
Toolbar is not hiding.
RecyclerView in not scrolling smoothly.
Here is my Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:background="#fff"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_below="#+id/toolbar"
android:id="#+id/recyclerView"
android:background="#fafafa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
use recylerView.setNestedScrollingEnabled(false); to make your scrolling smoother.
Create separate layout files for views and try. And include those into the list view.
<LinuearLayout ..>
<include layout="#layout/cv1"/>
<include layout="#layout/rv1"/>
<include layout="#layout/rv2"/>
<include layout="#layout/rv3"/>
</LinearLayout>
This is just a clue to you. I did solve similar issues long back in past. Please try experimenting with this clue.

Categories

Resources