This strange line appears in my view and don't know the reason
Edit 1: XML
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="320dp"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
</android.support.v4.widget.DrawerLayout>
Go on your XML file, take the DrawerLayout and cut it and put it on the tag before... so you will be able to see how it's designed.
So, put your LinearLayout of the DrawerLayout inside your visible view, edit it, and put it away again.
Sorry all, My Mistake. The shadow was causing this problem
mDrawer.setDrawerShadow(R.drawable.drawer_shadow_rtl, GravityCompat.END);
Related
I'm trying to create an application with fragment on the side as a menu bar.
My main problem is that when I open the fragment I can see the buttons behind it and even press them.
Of course I don't want that. I tried adding the property android:clickable="true" to the layout but it didn't help.
This is my 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="ibuy.ibuy.AddUpdateItem">
.
.
.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/search_image"
android:id="#+id/btnBrows"
android:onClick="openItemTable"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
.
.
.
<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="ibuy.ibuy.AddUpdateItem"
android:clickable="true">
<fragment
android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="Menus.smallMenu"
tools:layout="#layout/fragment_navigation_drawer"
android:alpha="255" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
This is the code of the listView of the fragment on other file:
<ListView
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:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#cccc"
tools:context="Menus.smallMenu"
android:clickable="true"/>
What am I doing wrong?
Thank you in advance!
I don't know what you meant by "I can see the buttons behind it". I assume you meant behind the DrawerLayout UI.
1)
In that case, you can use the attribute like android:layout_below="#id/btnBrows". As far as I know, all the UI elements should be positioned, otherwise they may be displayed one on top of another, like what you are seeing.
2) Also an issue is that both android:layout_width and layout_height of DrawerLayout is match_parent which fills up the whole screen. It competes screen space with the button. If the button is inside DrawerLayout, that would not be an issue but this might be your intentional design.
If you're into Android Studio, create a new Navigation Drawer Activity. Take a look at the main XML layout.
The DrawerLayout should be your root view. Inside it, you have the RelativeLayout with the buttons and the Fragment that is your navigation drawer.
That way, both are separated and the navigation drawer overlaps correctly when opened.
I have a navigation drawer and I have 5 items in that. What I want to do is I want the first 3 items in the list to display from the top than a gap in between and the next two items to be displayed from the bottom of the drawer.
How can I do this?
Basically I want to how can I customise my drawer.
I also want to know from where I can make icons for my navigation drawer.
Here the snapshot to my drawer
link
I suppose this post will help you :) Just change DrawerLayout and put here whatever you want
<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 to display Lists -->
<RelativeLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Listview to display on top slider menu -->
<ListView
android:id="#+id/list_top_slidermenu"
android:layout_width="240dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_gravity="start"
android:background="#color/list_background"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector" />
<!-- Listview to display on bottom slider menu -->
<ListView
android:id="#+id/list_bottom_slidermenu"
android:layout_width="240dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_gravity="start"
android:background="#color/list_background"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
I think you need to use a custom adapter like always when you want to have something different from standard. There you can add customs views as well.
See my answer here https://stackoverflow.com/a/25086380/2777381. this is a sample of an custom adapter.
My idea would be to ad 3 custom listview items, with your icon, then an emty view with specific height. and then again some more custom list items.
Edit:
Sample of an "empty" View which i use as separator line:
<View
android:id="#+id/viewSeparator"
android:layout_below="#id/linearLayoutDrive"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="20dp"
android:background="#color/separator"/>
I am new to android, I follow this tutorial to create Navigation Drawer here
I make the navigation drawer successfully but I dont know how to change framelayout to my custom layout with button, textview....My app just show menu and blank framelayout, how can I solve this ?
<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"
android:text="asdsadsad" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/purple_dark"
android:choiceMode="singleChoice"
android:divider="#android:color/darker_gray"
android:dividerHeight="0.1dp"
android:listSelector="#drawable/ic_drawer"/>
</android.support.v4.widget.DrawerLayout>
you can use a RelativeLayout on LinearLayout instead of FrameLayout and you can build your whole layout inside that
If you need to add another layout you need to gie it to your closeDrawerand drawerOpen.
Please refer my answer here
How can I create a navigation drawer like Google+ where there is a header for user profile info and a listview below?
I have the following code in my Activity:
<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="com.br.app.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="start"
android:name="com.br.app.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>
Currently, the NavigationDrawerFragment contains just a listview, but I tried to add a RelativeLayout as a container with an inner RelativeLayout to create the profile area and the listview below, but the app is crashing.
I've read the tutorial from but as I could understand, my header would be an item of the listview, and it won't be fixed on top (without scrolling).
How can I create this custom navigation drawer like Google+?
Actually, there are two version of navigation drawer used by google.
the first is the old navigation drawer BELOW the action bar. It is used in Google Play Store and Google Books for example.
HERE you can find a library that implements it.
The second is the new navigation drawer that is showed in Material Design guidelines where the drawer is over the action bar.
HERE you can find a library that implements it.
Actually these two libraries are in developing. But they are almost usable at this time.
You can easily customize the android Navigation drawer once you know how its implemented. here is a nice tutorial where you can set it up.
This will be the structure of your mainXML:
<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 to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
</android.support.v4.widget.DrawerLayout>
I notice that the drawers within the Google applications are scrollable, but I cannot for some reason come to the conclusion of how to achieve a scrollable DrawerLayout. I attempted to construct the layout file with the following design paradigm.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
But, with or without the ScrollView, the drawer just cuts items off at the bottom when they go beyond the end of the screen. I can't get any form of scrolling enabled. Not sure what I am missing or need to enable. Thoughts would be appreciated.
The LinearLayout in the DrawerLayout segment contains different styled views. One view displays title only with a divider below it, one displays an imageview with text next to it and another displays a title with a switch built into the row. So, multiple styled views need to be accounted for if done outside of XML coded layout files.
While using a ListView is a valid option, it was useful for me to attempt and resolve the situation for which I already had such a large XML file constructed for my layout in between the ScrollView above. As it turned out, there were only a few small modifications needed in order to get it working as intended. The latest layout file constructed is the following:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="#+id/scrollView"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize">
<LinearLayout
android:id="#+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
The main modifications required me to alter where the gravity and the margin existed. The gravity needed to be in the surrounding ScrollView otherwise it would cause odd behavior that didn't scroll or actually crashed in some instances apparently. Then the inner layout needed to be changed to 'wrap content'.
If the margin was not moved into the ScrollView as well, it apparently doesn't scroll down to the bottom. It left a margin of scroll unscrolled at the bottom. Once this was resolved, the DrawerLayout worked as was expected at this point. The ListView option also proposed is another approach to be used, but as mentioned at this point it was worth me analyzing it a bit further to re-use the code that I already had written; especially with several different custom views that would need to be handled inside the view.
It seems that it only works properly with a ListView. You will take less time to migrate to ListView than trying to make the ScrollView to work.
You should use a listview along with the frame layout. Something like this :
<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/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<ListView android:id="#+id/left_drawer"
android:layout_width="180dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
You can also refer to the Navigation Drawer documentation at developer.android.com. It has everything you will need.