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

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"/>

Related

Edittext keeps scrolling to its position inside RecyclerView

Prerequisites
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarFadeDuration="2"
android:scrollbars="vertical|horizontal">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
recyclerview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>
another_recyclerview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/divider_default_margin"
android:orientation="vertical"
android:showDividers="middle">
<...>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/anotherRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<...>
</LinearLayout>
edittext_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="wrap_content">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/formTextClearButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<...>
</androidx.constraintlayout.widget.ConstraintLayout>
Problem description
I am adding at runtime a recyclerview_layout.xml to the container inside main_layout.xml. The recyclerview_layout.xml sometimes contains another_recyclerview_layout.xml, which has a RecyclerView that has multiple view types, one of which is represented by edittext_item_layout.xml. When the latter exists in another_recyclerview_layout.xml and recyclerview_layout.xml is populated with some other items, the whole layout has a weird scrolling behavior, at the time the user taps on one of the TextInputEditTexts. It's like it tries to snap to the focused TextInputEditText and the user cannot scroll away from that view anymore. (See gif below)
Scrolling bug
Already tried solutions
Setting android:focusable="true" and android:focusableInTouchMode="true" to the direct child of the NestedScrollView, as you can already see in recyclerview_layout.xml. Also tried to add these properties to all the other containers (cry)
Setting android:descendantFocusability="blocksDescendants" to the parent of anotherRecyclerView. This solution does not work weel for me, since I need the TextInputEditText to be fully functional.
Listening to SoftKeyboard events and clearing focus as soon as the keyboard hides. This solution rises 2 other issues:
loses scroll position
the layout is still buggy, if the user tries to scroll while the keyboard is visible
Libraries
ConstraintLayout: 2.0.4
RecyclerView: 1.2.0
Material: 1.2.1
Help!
I am running out of ideas, any help is highly appreciated. Thank you!

how to navigation bar at the bottom

I have tied using this code..
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground" />
//parent views are Relative Layout then ScrollView
It is moving with the scrolling of the screen but I want navigation bar to be fixed, even after scrolling the screen, any can help me ??
Just like the Messenger app, I want it to be fixed!
-you can use following code or something like that....
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"/>
I got it! It's fixed and not affecting with scrolling root layout is Relative Layout.
Thanks for your help Mr Amit Ghoswani

How to make view container above Viewpager "scrollable" (Toolbar is inside Activity, not Fragment)?

I have fragment, which doesn´t cointains toolbar. Toolbar must stay in activity. This fragment must show main view and bellow viewpager with two fragments. Each fragment is specific. First use custom layout, second use adapter. Each has different height. I tried a lot of libs and ideas, but none of them works as it should (it made scroll longer/shorter than it should or it made crazy UI overlays).
I am trying to do UI where it looks that this all is one layout, meaning, it is scrollable from up to bottom. But I can´t figure it out. I was thinking to use CoordinatorLayout, but I have no idea how.
XML:
<?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="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#FF0000"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABCDEFGH" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GHIKJ" />
</LinearLayout>
<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>
How to make this as scrollable layout in fragment without using toolbar references?
Update: Yes, here are some pictures, I hope it is more clear now.
Wrap your LinearLayout inside an AppBarLayout. Actually AppBarLayout extends LinearLayout so you could just replace your LinearLayout with it.
Even if your app doesn't have a toolbar or an app bar, the AppBarLayout is the view that CoordinatorLayout coordinates with.
Adding the AppBarLayout should provide the behavior you're looking for.
This root fragment layout seems to working. I am not sure that this is best solution, but it works.
Note: I replaced listview by standard LinearLayout as root container and inflate child layouts (items) there.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</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.support.design.widget.CoordinatorLayout>
Child fragment (for viewpager):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/childFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</android.support.v4.widget.NestedScrollView>

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.

Two scroll views for two-sided navigation drawer hides toggle

I have spent a lot of hours trying to find the problem with ActionBarDrawerToggle, but the problem is in my main layout.
Let me show what the problem is.
Here is example, how it looks like initally after application start.
As you can see hamburger is present but not shown right now.
Than if swipe drawer menu it appears.
It looks as it should look like, but it can disappear suddenly, when for example invalidateOptionsMenu() was called.
So I have tried to find the problem with toggle, but it is in my layout
Here is my layout xml file.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear_layout_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:visibility="gone"
app:theme="#style/MainAppTheme.ToolbarMain"
app:titleTextAppearance="#style/MainAppTheme.Toolbar.Title" />
</LinearLayout>
<ViewStub
android:id="#+id/stub_progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="#+id/progress_bar_buttons"
android:layout="#layout/view_stub_progressbar_bg" />
</FrameLayout>
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fillViewport="true">
</ScrollView>
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fillViewport="true" />
</android.support.v4.widget.DrawerLayout>
The problem is in the last ScrollView, without last/right scroll view everything works fine. By the way this layout works fine with two drawers, but only hamburger is missed in this case.
I guess the problem is that navigation drawer toogle conflicts with two navgiation drawer view.
Because it doesn't matter what kind of view is with gravity end, it will not show hamburger in this case (if view with gravity end is present)
Please help to solve this problem, cause I have no idea how to deal with it, I need two drawers anyway.
Any help will be highly appreciated, thanks.
This is a pretty interesting issue but I think I have a solution. Well 2 solutions,
Have you creating a Frame Layout that houses two separate android.support.v4.widget.DrawerLayout layouts?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your content -->
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
the imbed the second drawer layout inside of the root
android.support.v4.widget.DrawerLayout.
sample xml
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your content -->
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"/>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
</android.support.v4.widget.DrawerLayout>

Categories

Resources