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
Related
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"/>
I have an activity layout that includes my fragment container this way,
<include
layout="#layout/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/background_container" />
and my fragment container is compose of linearlayout and a framelayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:padding="10dp">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent" />
</LinearLayout>
The problem is that I have to add my scrollable fragment in this container but the scroll doesnt seem to work. My layout goes like this
<ScrollView 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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
...
</LinearLayout>
</ScrollView>
I have tried several answer like
Using NestedScrollView
Adding minimum height to framelayout
Using fillViewport="true"
etc.
But nothing seems to work. Any idea what I've been doing wrong? Any help would be appreciated. Thanks in advance! Cheers!
Edit:
My activity layout contains navigation drawer, i dont know if it matter. And i add the view using
ft.replace(R.id.fragment_container, myFragment).commit();
i also dont know if fragment replace messes with my view. Please help. Thanks
it seems my fragment container's LinearLayout is missing orientation and also frameLayout
android:layout_height should be match_parent
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical" // orientation
android:padding="10dp">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" // match_parent
android:background="#android:color/transparent" />
</LinearLayout>
I'm trying to make the icons in a bottom navigation view lower. For example, right now they are pressed against the top line like this.
How would I make the icon lower? I want them to be centered vertically in the bottom navigation view.
xml:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.jchousurface.mastertrack.homescreen">
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</FrameLayout>
<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="#FFFFFF"
app:menu="#menu/navigation" />
</LinearLayout>
use
bottomNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
or
app:labelVisibilityMode="unlabeled"
change attribute android:layout_height="40dp" or lower in BottomNavigationView
Actually there is already similar question
BringToFront doesn't work inside a coordinator layout
However no of suggestions helped me to make bringToFront work within a coordinatorlayout.
Here is the layout-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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:id="#+id/navigation_drawer_container"
android:name="..."
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/..."
android:clickable="true"
android:layout_gravity="bottom|end"
android:layout_marginRight="20dp"
android:layout_marginBottom="60dp"
app:borderWidth="0dp"/>
<CustomView
android:id="#+id/customview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone"
app:layout_behavior="..."/>
</android.support.design.widget.CoordinatorLayout>
The custom view is inherited from FrameLayout. It can change its height.
To bring the custom view to the front first I tried to add:
mCustomView.bringToFront();
Then
mCustomView.requestLayout();
mCustomView.invalidate();
Finally also
((View)mCustomView.getParent()).requestLayout();
But without success. The button is still on the top.
Did I missed anything?
Maybe there other possibilities to bring the custom view to front or to put the button under custom view?
I also tried to add a behaviour to the button, but since it's visibility depends not only on the custom view I thrown this approach away.
Thank you for any help in advance.
I finally found a workaround - if I set setEnabled(false) on the AppBar, it goes to the background and I can draw other stuff over it regardless of API level.
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>