ImageView is not showing in Drawer? - android

I have simple DrawerLayout which contains some main content (they all display nicely), a navigation drawer which is only a RelativeLayout (id: drawerPane) and ListView (which I filled with BaseAdapter).
My goal is to insert some image above navigation items in the drawer. I tried inserting that image (from within drawerPane of course) by encapsulating it in LinearLayout, RelativeLayout, placing it on its own, but image is not showing.
How to insert that image in Drawer above navigation items?
Here is XML with short comments.
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.ProfileActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<!-- Add this, so AppBarLayout has a bug, which causes ViewPager not to show listview entirely on the screen
Adding this view fixes (workaround) the problem -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimary" />
<androidx.appcompat.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"
app:layout_scrollFlags="scroll|enterAlways">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center|top"
android:background="#android:color/white"
>
//Here I have bunch of small components which are displayed nicely
</LinearLayout>
<!--Navigation drawer-->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="#+id/drawerPane"
android:layout_gravity="start">
<!--Profile box here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_gravity="start">
<!--This is the image which I cannot place in the drawer. Busting my head for daaays.-->
<ImageView
android:layout_gravity="start"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="#drawable/welcome_logo"
android:layout_above="#+id/drawerList">
</ImageView>
</LinearLayout>
<!-- List of Actions (pages) -->
<ListView
android:id="#+id/drawerList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>

Related

RecyclerView does not scroll while searching

I have a recyclerview assoicated with a filtered search in a toolbar. When I start the search, the number of items displayed by the recyclerview is far larger than the screen size. But when I try to scroll up by swiping to look at the elements off the screen, there no response. I thought RecyclerViews like ListViews always support scrolling. Any ideas why my RecyclerView is not scrolling?
Here is the coordinator layout for the tool bar, search, and recycler view that gets included in my main layout (I apologize for the formatting but the insert code widget does not work correctly):
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.lampreynetworks.cpa.CPA_Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_search_id"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorToolbarBackground"
android:theme="#style/AppThemeDark"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
The main layout is as follows
<?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/base_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.lampreynetworks.cpa.CPA_Activity"
android:orientation="vertical">
<include
android:id="#+id/toolbar_search"
layout="#layout/toolbar_search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/borderLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="#drawable/text_view_border"
android:orientation="vertical">
<TextView
android:id="#+id/text_connect_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="some text"
android:textColor="#color/orange"
android:textStyle="bold"/>
</RelativeLayout>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/borderLayout"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:choiceMode="none"
android:stackFromBottom="false">
</ListView>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/nav_drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
All other aspects appear to be okay. The list interactively responds to user input text and click actions on the recyclerview items are able to obtain the searched-for information. But this list never scrolls. I have tried numerous approaches taking hints from related issues (adding various types of scroll layouts, invoking scroll-related attributes in various places, etc. all within the coordinator layout) but the behavior remains unchanged. There must be something really stupid that I am doing to kill such a basic behavior.
Try moving the RecyclerView outside of the AppBarLayout as follows:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.lampreynetworks.cpa.CPA_Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_search_id"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorToolbarBackground"
android:theme="#style/AppThemeDark"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
change recyclerview height to wrap_content.
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
put your recyclerview out of AppBarLayout.

Hide Toolbar and footer when scrolling up

I want to use the CoordinatorLayout in one of my activities.
The layout of the activity contains a Toolbar in the top, a RecyclerView in the middle, and a RelativeLayout at the bottom (the footer).
I would like to hide the Toolbar and the footer when the user swipes up the RecyclerView.
What I achieved so far:
When I swipe up, the Toolbar hides, but the footer (which was hidden before) reappears. I want the Toolbar and footer to be linked somehow, so that they hide at the same time when the user swipes.
I've heard about Behaviors but I don't know how to create them (I'm just using the default one).
My activity layout:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- toolbar -->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
....
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
....
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:layout_alignParentTop="true">
<!-- content -->
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
<!-- footer -->
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
....
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/right_drawer"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="end"
android:divider="#android:color/transparent"
android:dividerHeight="1dp"
android:background="?attr/drawerBackgroundColor"/>
</android.support.v4.widget.DrawerLayout>

Grey Background Above Main Content in Android Because of Margin

I can't seem to get rid of this grey bar because of my margin in the below XML that is set to the ActionBar height. Eventually an actionbar appears but transparent but how do I get rid of this grey background from the start? If I use paddingTop then my actionbar is not clickable.
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical">
<include
android:id="#+id/action_bar"
layout="#layout/action_bar" />
</RelativeLayout>
<FrameLayout
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="#+id/left_drawer"
android:background="#FFFFFF"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
Use a RelativeLayout parent for all other layouts inside your Drawer.
And set the FrameLayout to stay below the appBar, like that:
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/action_bar_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical">
<include
android:id="#+id/action_bar"
layout="#layout/action_bar" />
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/action_bar_container" />
<ListView android:id="#+id/left_drawer"
android:background="#FFFFFF"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:choiceMode="singleChoice"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
This should work, it should move the frame layout below the action bar only if it's visible!
This can help you...
or try to add custom toolbar... make a separate layout file with the content like below`
<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/gradient"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
`
and include it with include tag in your drawer layout... Get the toolbar by findViewById(...) and set it using setSupportActionBar(Toolbar toolbar) method.

Relative layout always seems to work for only drawer layout or frame layout, both child doesn't work together

I have a relative layout in which i have two child .one is drawer layout and the other is a frame layout in which i have used a fragment .The problem is when i keep drawer layout in the top and the frame layout in the bottom,drawer layout doesn't work and if do the opposite,frame layout doesn't
this is my relative layout
<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">
<include
android:id="#+id/toolbar_actionbar"
layout="#layout/mtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"
android:layout_alignParentStart="true"
tools:layout="#layout/fragmentfloating"
android:layout_alignTop="#+id/drawer"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar"
android:layout_alignParentBottom="true">
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:layout_gravity="start">
</ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Mike M. is absolutely right: you need to keep FrameLayout as one of the Children of DrawerLayout.
I've updated your XML a bit, take a look:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<FrameLayout
android:layout_below="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_gravity="center_horizontal|bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.rohit.newmastervocab.FloatingFragment"
android:id="#+id/fragment2"/>
</FrameLayout>
</RelativeLayout>
<ListView
android:id="#+id/drawerlist1"
android:layout_width="240dp"
android:layout_height="match_parent"
android:entries="#array/navigation_items"
android:background="#F3F6C8"
android:fitsSystemWindows="true"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
Now drawer works just as expected and Fragment is stick to the bottom|center of the screen.

set background for activity containing AppbBarLayout

I am trying to use androids CoordinatorLayout and FrameLayout. What I want to have is a
toolbar
LinearLayout showing some info
tablayout
listviews
when the listviews are scrolled the toolbar and the LinearLayouts should scrollup and hide and the tabs should go at the top.
I have a layout of the type:
<android.support.v4.widget.DrawerLayout
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:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<-- stuff I want to hide on scrolling -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:orientation="vertical">
<include
layout="#layout/toolbar"
app:layout_scrollFlags="scroll|enterAlways"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gamercard content"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="More Gamercard content"
/>
</LinearLayout>
</LinearLayout>
<-- stuff I dont want to hide on scrolling -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:scrollbars="horizontal"
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<!-- My Scrollable View -->
<include layout="#layout/nested_scrolling_container_view"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
What I want to do is have a picture as the background for the entire activity, but what I see is that the AppBarLayout part is always dark. Please help.
I could do it programmatically by setting the backgroundColor in code to Color.TRANSPARENT.
appbar.setBackgroundColor(Color.TRANSPARENT);

Categories

Resources