Play video upon a Fragment but below Navigation Drawer - android

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.

Related

Spinner can be clicked on top of Navigation menu

I have a navigation menu with some items. The problem that I am facing is the Spinner items and other UI elements which is underneath the menu when it is open remains clickable even when the menu is on top of those, as explained in the figure.
Here is my activity layout files.(activity_main.xml)
<?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="match_parent">
<Spinner
android:id="#+id/delivery_area_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:gravity="center"
android:spinnerMode="dropdown" />
<include layout="#layout/layout_drawer_navigation" />
</RelativeLayout>
This is my navigation drawer layout.
<?xml version="1.0" encoding="utf-8"?>
<merge 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="wrap_content"
android:layout_height="wrap_content"
android:clickable="true">
<android.support.v4.widget.DrawerLayout
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="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/layout_main_navigation_header"
app:menu="#menu/main_drawer_menu" />
</android.support.v4.widget.DrawerLayout>
I tried to look for solutions and found that for many people setting android:clickable="true" does the trick but in my case that is also not working.'

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...

Android studio navigation drawer not fitting correctly

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>

NavigationView headerlayout not scrolling

I have simple question! I am stuck on it. I have seen plenty of answers and tried everything that I can.
Here is my DrawerLayout:
<?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:context=".BaseNavDrawerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<include
android:id="#+id/toolbar"
layout="#layout/layout_toolbar" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_drawer_header_layout"
app:itemBackground="#color/white"
app:itemTextColor="#color/nav_text_color_selector"
app:itemIconTint="#color/nav_text_color_selector"
app:menu="#menu/nav_drawer" />
</android.support.v4.widget.DrawerLayout>
And this is my nav_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="200dp"
android:gravity="bottom"
android:background="#drawable/drawer_cover">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/google_logo"
android:id="#+id/image_account"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="17dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner_accounts_list"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:spinnerMode="dropdown"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_marginEnd="22dp"
android:layout_marginRight="22dp" />
</RelativeLayout>
When I scroll NavigationDrawer, only NavigationView get scrolled but headerlayout(nav_drawer_header_layout) remains still and doesn't scroll at all.
I know DrawerLayout scrolls completely but I am stuck here.
What I am doing wrong?
EDIT-1
Java code snippet:
mNavViewHeaderLayout = LayoutInflater.from(EmailActivity.this).inflate(R.layout.nav_drawer_header_layout, mNavigationView);
mSpinnerAccounts = (Spinner)mNavViewHeaderLayout.findViewById(R.id.spinner_accounts_list);
You need to do two things.
remove app:headerLayout="#layout/nav_drawer_header_layout" from your NavigationView.
Inflate header in your navigation view at run time.
View headerLayout = navigationView.inflateHeaderView(R.layout.nav_header_home);
TextView txtContact = (TextView) headerLayout.findViewById(R.id.txtContact);
TextView txtHeaderLogoName = (TextView) headerLayout.findViewById(R.id.txtHeaderLogoName);

NavigationDrawer blocks other button on the activity

I'm working on the UI of my app and I'm facing a problem when I implement the Navigation Drawer. As you can see here, I have some buttons to manage my Media Player, these are not responding to my clicks when I implement the Navigation Drawer (working fine without Navigation Drawer).
I think the problem is coming from my XML file because there are no changing when I delete the implementation in Java.
Here are my XML sheets :
main_activity.xml
<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"
tools:context=".MyActivity">
<fragment
android:id="#+id/fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.ilan.myapplication.fragments.FragmentHome" >
</fragment>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Buffering"
android:id="#+id/tV_Buffering"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
<include
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
layout="#layout/player_controls"
android:layout_alignParentBottom="true"/>
<include
layout="#layout/navigation_drawer_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Note that I put the Navigation Drawer in the end to have it to cover the all activity.
navigation_drawer_main_layout.xml
<?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">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFFFFF"/>
</android.support.v4.widget.DrawerLayout>
player_controls.xml
<?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="match_parent"
android:background="#color/blue">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/button_play_pause"
android:layout_toStartOf="#+id/tV_Buffering"
android:background="#drawable/bouton_play"
android:layout_centerInParent="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:id="#+id/button_stop"
android:layout_toRightOf="#id/button_play_pause"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"/>
</RelativeLayout>
Well, if anyone has any idea from where this come from it would be awesome, thanks !
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width. Check out the documentation of google regarding to DrawerLayout : https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html.
Your primary content should put inside DrawerLayout instead of including the DrawerLayout inside your RelativeLayout.
For your case, you could try to implement it this way instead:
main_activity.xml
<?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">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<fragment
android:id="#+id/fragments"
class="com.example.ilan.myapplication.fragments.FragmentHome"
android:layout_width="match_parent"
android:layout_height="match_parent">
</fragment>
<TextView
android:id="#+id/tV_Buffering"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:text="Buffering"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<include
layout="#layout/player_controls"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_weight="1"/>
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

Categories

Resources