ScrollView as a first element in Navigation Drawer - android

I'm trying to create a navigation drawer that looks like google play store. What I've noticed in google play store drawer is that it's scrollable top to bottom (not only the listview). I managed to create a beautiful drawer that opens and closes correctly. But when I use a scrollview as a first element in drawer layout, navigation drawer glitches and shows up always on the screen as a scattered layout.
I use this code (I removed scrollview content for clarity, plus, even just one LinearLayout with 2-3 simple buttons in it, is enough to show the glitch, so it's irrelevant):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main Layout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:id="#+id/screen"
android:layout_height="wrap_content"
tools:context=".Intro"
android:weightSum="1">
</LinearLayout>
<!-- Drawer Layout -->
<ScrollView
android:layout_width="270dp"
android:layout_height="match_parent">
....
....
...
</ScrollView>
Note that I used fixed height elements in the scroll view, and also removed ALL the listviews & expandable list views (views with auto scrolling) without any luck.

I used navigation drawer as following:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left"
android:name="com.xxx.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
And inside the fragment layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/white"
tools:context=".com.xxx.NavigationDrawerFragment">
<ScrollView
android:id="#+id/list_drawer_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

Related

Header of NavigationView not showing unless there is margin to top

I am creating an Android app which got a navigation drawer in a layout:
<?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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/navigation_select_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/navigation_drawer_header_layout"
app:menu="#menu/main_drawer_options" />
</android.support.v4.widget.DrawerLayout>
the navigation_drawer_header_layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textViewButtonCloseDrawer"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="X"/>
</RelativeLayout>
The header layout is added but not showing unless I add either a top margin for the TextView or some padding to the RelativeLayout which pushes the TextView down.
Why won't it show as defined in the header layout? Why is the need to push the layout in order for it to be shown?
As understood from the comments, you got a ToolBar which hides the content instead of staying above it at all times. Check out this answer here which might solve your problem:
Display content under toolbar

Android DrawerLayout overlays background ListView

Got activity with ListView and Navigation Drawer which unfortunately overlays my ListView and I cannot have any interaction like 'onItemSelected' with it.
That's how it looks like:
But
Whenever I change DrawerLayout to not cover whole activity but just
a small piece, .
onitemSelect is working
Below my layout code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="marcin.chruscicki.notefication.MainActivity"
android:background="#color/universalBackground_DarkGray">
...
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/notesListView"
android:stackFromBottom="false"
android:layout_alignParentStart="true"
android:layout_above="#+id/versionTxtView" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#262626" />
</android.support.v4.widget.DrawerLayout>
...
</RelativeLayout>
I cannot find answer anywhere and I am sure this is just a simple thing to fix.
The reason your list view is not working is because u placed it in the bottom layer and over it you placed a drawer so the drawer is over the listview and the drawer is set to match_parent
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="marcin.chruscicki.notefication.MainActivity"
android:background="#color/universalBackground_DarkGray">
...
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<!-- The main content view -->
<android.support.design.widget.NavigationView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="#+id/nav"/>
</android.support.v4.widget.DrawerLayout>
...
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/notesListView"
android:stackFromBottom="false"
android:layout_alignParentStart="true"
android:layout_above="#+id/versionTxtView" />
</RelativeLayout>
try to place the list view like this when you make a item in the layout it goes one over another that means the last you place the item will be at the front
you need to make the navigation drawer listviw in the fragment layout .Here is a full example how you can dofragment example .hope this will help you.Try to make a fragment for navigation drawer its easy .
I think I just found a solution/workaround for my problem. Instead of putting Drawer Layout between other components like TextView or ListView I used tutorial linked by #neelay-srivastava and created new class + layout with alone DrawerLayout inside. Then changed all my activities to fragments. And it works.
For futher users with same problem just remember to do not nest DrawerLayout in another activity layout between other components.

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>

Adding fab Button at the junction of two ViewPager widgets

I have implemented a navigation drawer. In the FrameLayout of navigation drawer I have added a fragment which contains 2 ViewPagers taking exactly half the screen each. Now I want to add a FAB button at the junction of these two viewpagers as shown here.
In my case both viewpagers occupy exactly half screen which is slightly different from what is shown in image. Can somebody help me in getting the FAB at the junction.
The code for the fragment containing the 2 viewpagers is below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/shirt_section"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pant_section"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
You could enclose your linear layout into FrameLayout and add your button like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</LinearLayout>
<ImageButton
android:layout_gravity="center_vertical|right"
...
/>
</FrameLayout>

Android Collapsible & Expand Linear Layout

Basically I am trying to do an animation for layout upon user on touch the button. Here is the explanation:
I have a base mapview and on top of that, I am trying to put a linear layout to shows news feed. And normally the linear layout will be collapsed with an expand button. So when user on touch and drag down the button, the linear layout will expand.
I have experienced with this using JQuery and Javascript. However, I have no idea how to do this in Android.
I have found some researches: Tutorial and I not sure how to implement it. And here is my layout.xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
initExtent="21801.3, 25801.0, 33218.7, 44830.0">
</com.esri.android.map.MapView>
</FrameLayout>
<LinearLayout
android:id="#+id/navDrawerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/nav_left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dimgrey"
android:choiceMode="singleChoice"
android:divider="#CCCCCC"
android:dividerHeight="0.5dp"
android:groupIndicator="#null">
</ExpandableListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Any guides? Thanks in advance.

Categories

Resources