Remove left margin from materialdrawer - android

How to remove the space Mikepenz Material Drawer.I used custom layout for profile menu and drawer Items. I didnt set Margin or padding for those views. And i also tried activity horizontal margin to 0.
Help would be appreciated. same margin right side also. Profile menu is Ok. it has no problem.whereas draweritem facing the problem.
Below code is Profile Menu
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imgUserProfileImage"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="#dimen/min_margin"
android:src="#drawable/parent" />
<com.CustomTextView
android:id="#+id/txtUserName"
style="#style/label_text_primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="Noorul"
app:font="#string/montserrat_semi_bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.3dp"
android:layout_marginTop="#dimen/min_margin"
android:layout_marginLeft="#dimen/min_margin"
android:background="#999999" />
</LinearLayout>
</LinearLayout>
And Below Code is for Drawer Item Menu
<?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"
android:id="#+id/lnrSecond_menu"
android:layout_width="match_parent"
android:layout_height="#dimen/material_drawer_item_secondary"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<View
android:id="#+id/view"
android:layout_width="3dp"
android:layout_height="match_parent"
android:background="#color/primary"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="#+id/material_drawer_icon"
android:layout_width="#dimen/profile_img"
android:layout_height="#dimen/profile_img"
android:padding="#dimen/most_most_normal_margin"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|start"
android:orientation="vertical">
<com.CustomTextView
android:id="#+id/material_drawer_name"
style="#style/label_text_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|start"
android:textDirection="anyRtl"
android:text="Some Secondary Text"
app:font="#string/montserrat_regular"
/>
<com.CustomTextView
android:id="#+id/material_drawer_description"
style="#style/label_text_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:visibility="gone"
app:font="#string/montserrat_regular"
android:text="Some drawer text" />
</LinearLayout>
<LinearLayout
android:id="#+id/material_drawer_badge_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right|center">
<com.CustomTextView
android:id="#+id/txtMenuBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/min_margin"
android:gravity="center"
android:text="99" />
</LinearLayout>
</LinearLayout>
Where I made the Mistake? Help me i will be grateful to you guys.

The drawer adds this padding because it is default for all items inside the Material Design Guidelines. As there is an issue with API 17 I have to set this programatically in this line:
https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/model/BasePrimaryDrawerItem.java#L104
You might also want to post the DrawerItems you use, as the screenshot does not look like you use the default items.
If you already create your own CustomDrawerItem you just want to set the padding to 0px again (If you extend from the BasePrimaryDrawerItem) If you do not extend from it you should be fine.
The drawer does not set this padding on the items anywhere else than here.

Related

CardView and other elements are not being displayed in my xml file

I am using an AppCompatActivity and at the moment, I am trying to add a navigational drawer to the toolbar.
Problem is, now the cardview is not being displayed and the navigational drawer is also not working.
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cards"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Username"
android:id="#+id/usersName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Others"
android:id="#+id/others"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"></android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Would really mean a lot and make my day if someone could fix my error please. I don't know where I have gone wrong, and I just want to have the navigation drawer button in the toolbar and the cardview on the screen
Youre trying to squeeze a 200dp cardview inside a 150dp container. Use match_parent for drawerlayout.
Then, straight from the developer guides:
The main content view must be the first child in the DrawerLayout because the XML order implies z-ordering and the drawer must be on top of the content.
The main content view is set to match the parent view's width and height, because it represents the entire UI when the navigation drawer is hidden.
For more information follow the developer resources
Try this solution, this has android:layout_gravity="start" in NavigationView and CardView android:layout_height="match_parent" and some other minor changes.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cards"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:padding="15dp">
<TextView
android:id="#+id/usersName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Username"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/others"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Others"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Android layout objects placement

I have this simple activity in my android app but I don't know how to place my button so it appears at the same position on various screen sizes.
I want the button to always be placed at the bottom of the screen. The screenshot shown is from a phone screen. When displayed on a larger screen the button is higher up.
How can I fix this?
Thanks
See this screenshot
You can use RelativeLayout with this parameter (android:layout_alignParentBottom="true")
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click Me!"/>
</RelativeLayout>
You should use a RelativeLayout
If you have a RelativeLayout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.
If your button at the bottom doesn't show then probably the layout above it takes all the space. In this case you can put the button first in your layout file and position the rest of the layout above the views with android:layout_above.
Have a look a RelativeLayout. Use this ViewGroup and add a Button inside it with alignParentBottom
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<Button
android:id="#+id/button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentBottom="true"
android:text="HORAIRE"
android:layout_margins="<your_margin_in_dp>" />
</RelativeLayout>
Make footerButton.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="HORAIRE"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
And add it in all your layout file like below line:
Android Activity_Layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Footer aligned to bottom -->
<include layout="#layout/footer" />
<!-- Content above footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content goes here"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Hope it will solve your problem
This is what I ended up doing. Thanks to everyone who posted, it helped me get in the right direction!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context="xxxx.MainActivity"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dernières nouvelles Twitter"
android:id="#+id/textView"
android:textStyle="bold"
android:textSize="17dp"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp"
android:layout_alignParentTop="true"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView_tweets"
android:layout_above="#+id/buttonDisplay"
android:choiceMode="none"
android:paddingTop="25dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Horaire"
android:layout_margin="5dp"
android:id="#+id/buttonDisplay"
android:onClick="buttonGotoDisplay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

Android ListView with CardView: Last Card not fully displayed when scrolling

I have created a ListView to which I've added CardView.
As you can see in the image, when I start scrolling, the last Card in the ListView is not completely displayed. It scrolls up but it does not come above Android's navigation bar at the bottom. I've been testing on a HTC One M8.
Here is the ListView:
<?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="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/wanna_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="#null"/>
</LinearLayout>
And here is the CardView that I inflate and set into the adapter of the listview:
<?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.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/cv"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
card_view:cardCornerRadius="6dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="2dp">
<!-- compat padding is required if using AppCompat -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" >
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/thumbnail"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
android:src="#drawable/india"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/firstLine"
android:layout_toRightOf="#+id/thumbnail"
android:layout_alignParentTop="false"
android:textSize="20sp"
android:text="Tennis with Peter"
android:layout_alignTop="#+id/thumbnail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/secondLine"
android:layout_below="#+id/firstLine"
android:text="10 Oct at 7pm"
android:layout_alignLeft="#+id/firstLine" />
<Button
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="YES"
android:id="#+id/button3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignLeft="#+id/thumbnail" />
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="NO"
android:id="#+id/button4"
android:layout_toRightOf="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I have also tried my card view layout without wrapping it in a LinearLayout and it still does not work.
Is there a setting in the layout xml that will take care of this?
Thanks in advance.
android:layout_marginBotton=" "
add margin bottom should try once.
So adding a margin to the bottom of listView worked, as below:
<ListView
android:id="#+id/wanna_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:layout_marginBottom="80dp" />
Am surprised this is the only way to get it to work though. I would have assumed the Android framework took care of these things.
Is the ListView in a Fragment ? As far as I know, this is possible when you have used a Toolbar such as :
<android.support.v7.widget.Toolbar
...
app:layout_scrollFlags="scroll"
...
>
</android.support.v7.widget.Toolbar>
then change the attribute to:
app:layout_scrollFlags="enterAlwaysCollapsed"
Adding margin at the bottom of ListView is sort of a hack. I have given a probable cause for this. If this is the case, then you won't need to add the margin in ListView. There is always a reason behind the UI behavior. I hope this helps.

Android Toolbar layout is horizontal

I'm trying to use a couple views within a support.v7.widget.Toolbar, but it looks like they're all placed as if in a horizontal LinearLayout. I'm looking to create something more like this where the EditText ends past the overflow menu, rather than where the overflow menu begins. Here's my currently layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="250sp"
android:background="#color/primary"
android:gravity="bottom"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button_id"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/url"
android:textColor="#color/accent"
android:textSize="16sp" />
<EditText
android:id="#+id/url_text_field_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:maxLines="1" />
<TextView
android:id="#+id/output_text_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/initial_output_text_id"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Here's a screenshot. You can see the views are in line with the share button and overflow menu. The title is also hidden on the left hand side by the views. How would I have a second row for my views in the Toolbar so they span the width of the page? Hopefully, I'm just missing something small, as I'm new to Android. Thanks in advance for the help.
You could, probably, put a vertical LinearLayout into your Toolbar

Hide a layout when focus on it is lost in XML

I have the following xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/FrameLayout"
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/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="#+id/musicLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp"
android:focusable="true"
android:visibility="visible" >
<ImageView
android:id="#+id/backward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/backward" />
<ImageView
android:id="#+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:src="#drawable/stop" />
<ImageView
android:id="#+id/pausePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:src="#drawable/play" />
<ImageView
android:id="#+id/forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="10dp"
android:src="#drawable/forward" />
</LinearLayout>
The framelayout is for an actionbar with tabs which are the viewpager in the above layout. The actionbar works perfect. The problem that I want to solve is that the last linearlayout, which is actually a media player floating in the bottom of the screen, needs to be hidden when I press outside the linearlayout! I have tested the onfocuschangelistener in the musicLayout and onclick in the pageviewer but nothing happens! What am i doing wrong?
Edit:
In case it helps, every tab is a fragment with its own layout which is added to the viewPager.
I think the easiest solution to this problem would be to add a transparent view that matches parent of your ViewGroup. Basically, you would have the ViewPager, LinearLayout and View at the same level. You can then register an onClickListener on your transparent View and that should do the trick.
Layout should be something as simple as this :
<View android:id="#+id/transparent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>

Categories

Resources