Android studio navigation drawer not fitting correctly - android

I've thoroughly searched but couldn't find my answer, sorry if this a stupid post.
My navigation drawer won't set when I declare android:layout_gravity="start" I've been trying to solve this issue however I cannot find it anywhere online. I was wondering if anyone could point me in the right direction. Here is a screenshot of what it navigation drawer looks like on a S7 device.
https://i.stack.imgur.com/OL8re.png
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/activity_homepage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="mypackagename.homepage">
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
app:headerLayout="#layout/navigation_header"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
<include layout="#layout/navigation_action">
</include>
<Button
android:text="Add a post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="74dp"
android:id="#+id/addNewPost"
android:onClick="addNewPost"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<include layout="#layout/main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</include>

Related

Text won't appear in TextView

I am making a Navigation Drawer in my Android app. The Navigation Drawer has an Header which includes a Account Icon and a Text View. But when I run the App, I can no longer see the Icon or the TextView.
This is what I have been getting,
Here is my code for my navigation drawer activity_admin.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.vishistvarugeese.ongc_app.AdminActivity">
<android.support.design.widget.NavigationView
app:headerLayout="#layout/admin_nav_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/white"
app:itemIconTint="#color/black"
app:itemTextColor="#color/colorAccent"
app:menu="#menu/admin_menu"
android:layout_gravity="start"
app:theme="#style/menu_style">
</android.support.design.widget.NavigationView>
This is the code for my navigation header, admin_nav_header.xml
<?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="160dp"
android:background="#drawable/headernav"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/ic_account_circle_white_48dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/navUserName"
android:text="#string/name"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_marginTop="10dp"/>
</LinearLayout>
This is what I was trying to do
Can someone please help me with the issue?
Remove theme and other property from NavigationView.
<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:background="#color/homeDrawerColor"
android:fitsSystemWindows="true"
app:headerLayout="#layout/admin_nav_header"
app:menu="#menu/admin_menu" />
If not work then give a direct string to check any problem in string.xml or not...

NavigationView with ExpandableListView not scrolling

I have a problem within my NavigationView.
I created the view from the standard forms in Android Studio and then changed it so that it looks as i want , but i have 2 problems.
While working on it i saw that i cannot use the standard menu items because i need custom layouts in my menu items. So i implemented that as ExpandableListView.
When i expand the ExpandableListView (quite standard with own
adapter) the image blow is overlapping my list items.
The second issue is that if i expand all, but not all child are shown
and the scrolling doesn't work.
Does someone have a hint how i can accomplish this ?
Here's my code:
<?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"
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">
<include
layout="#layout/app_bar_dash_board"
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="wrap_content"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header_dash_board">
<!--app:menu="#menu/activity_dash_board_drawer">-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/navigationmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="192dp"
android:background="#android:color/white"
android:groupIndicator="#null"
android:soundEffectsEnabled="false">
</ExpandableListView>
</LinearLayout>
<ImageView
android:id="#+id/img_logo"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="bottom|center"
android:contentDescription="#string/its_just_a_logo"
app:srcCompat="#drawable/logo" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Overlay icon over relative layout in Drawer layout?

I want to integrate a button over relative layout over navigation drawer. Could someone help me please?
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
<!-- The navigation drawer -->
<RelativeLayout
android:id="#+id/rela"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginRight="-20dp"
android:background="#android:color/black"></RelativeLayout>
<RelativeLayout
android:id="#+id/relad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#android:color/black">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/radiobutton_off_background"
app:fabSize="normal"
android:layout_marginLeft="-20dp"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
My floatin button appear inside. But cannot able to overlay it

strange issue when using drawer in Android lollipop

I have mainlayout.xml as coded below:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
tools:context="com.sanwix.mh.meeting.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/layout_appbar"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/MyMainReycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:padding="16dp">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/Fabb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="left|bottom"
android:layout_margin="16dp"
android:src="#android:drawable/ic_menu_edit"
android:transitionName="sharedFab"
app:backgroundTint="#color/colorAccent"
app:elevation="8dp"
app:fabSize="normal"
/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/myRecycleDrawer"
android:layout_width="280dp"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
every things work perfectly on pre-lollipop devices.
but on lollipop or above, it doesn't run perfectly.
my issue is that: I have no main content for myactivity
and each one of my elements take a seperate drawer .
I mean the RelativeLayout will be shown as left-side drawer
and the RecyclerView will be shown as right-side drawe on lollipop or above.
but
what I want is just one drawer on rightside(my recycle)

Play video upon a Fragment but below Navigation Drawer

I am trying to write a simple code to play video form raw folder and I have to play video on fragment but my activity has a navigation drawer so when I have tried to play this video at first time there is only voice no video so I search for this problem then I got a solution videoView.setZOrderOnTop(true) but now there is another issue I faced that is the video window comes upon the navigation drawer.this is the screen shot what is happing
hear is my xml layouts
This is for activity
<?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"
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">
<include layout="#layout/app_bar_main"
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/nav_header_main"
app:menu="#menu/activity_main_drawer"
style="#style/textDisply2.title"
>
<TextView
android:id="#+id/nav_call_sleep_care"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:background="#color/buttonColor"
android:gravity="center"
android:drawablePadding="#dimen/column_padding"
android:drawableLeft="#mipmap/call_care_small"
android:textColor="#android:color/black"
android:textSize="#dimen/home_wh_btn_txt"
android:text="#string/call_sleep_care" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
and This is my fragment 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"
android:background="#android:color/transparent"
>
<TextView
android:id="#+id/screen_name"
android:text="#string/video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.AppCompat.Title"
/>
<LinearLayout
android:layout_below="#+id/screen_name"
android:id="#+id/video_dis_box"
android:layout_marginTop="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/play_video_btn"
android:layout_width="#dimen/img_btn_height_play"
android:layout_height="#dimen/img_btn_width_play"
android:src="#mipmap/music"
/>
<LinearLayout
android:padding="#dimen/column_padding"
android:orientation="vertical"
android:layout_weight="1"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/video_title"
android:text="#string/video_title"
style="#style/textDisply2.subHead"
/>
<TextView
android:id="#+id/dr_surendra"
android:text="#string/dr_surendra"
style="#style/textDisply2.subHead"
android:textSize="#dimen/home_color_btn_txt"
/>
</LinearLayout>
<ImageView
android:id="#+id/lock"
android:layout_width="#dimen/img_btn_height_lock"
android:layout_height="#dimen/img_btn_width_lock"
android:src="#mipmap/lock"
/>
</LinearLayout>
<VideoView
android:layout_below="#+id/video_dis_box"
android:id="#+id/play_video"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
please suggest me the solution.
I think that to invoke videoView.setZOrderOnTop(true) is non-sense.
What I think you have better to do is to close the Navigation Drawer.
So somewhere in your code for example:
DrawerLayout drawerLayout = (DrawerLayout) findViewById(drawer_layout);
NavigationView navigationView = (NavagationView) findViewById(nav_view);
drawerLayout.closeDrawer(navigationView);
will close the Drawer and the VideoView won't be hidden.
Note: the code to close the Drawer may differ depends on your situation.

Categories

Resources