Reputation: 61
Got activity with ListView and Navigation Drawer which unfortunately overlays my ListView and I cannot have any interaction like 'onItemSelected' with it.
But
Whenever I change DrawerLayout to not cover whole activity but just a small piece, .
Below my layout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="marcin.chruscicki.notefication.MainActivity"
android:background="@color/universalBackground_DarkGray">
...
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/notesListView"
android:stackFromBottom="false"
android:layout_alignParentStart="true"
android:layout_above="@+id/versionTxtView" />
<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"
android:fitsSystemWindows="true"
>
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#262626" />
</android.support.v4.widget.DrawerLayout>
...
</RelativeLayout>
I cannot find answer anywhere and I am sure this is just a simple thing to fix.
Upvotes: 4
Views: 684
Reputation: 61
I think I just found a solution/workaround for my problem. Instead of putting Drawer Layout between other components like TextView or ListView I used tutorial linked by @neelay-srivastava and created new class + layout with alone DrawerLayout inside. Then changed all my activities to fragments. And it works.
For futher users with same problem just remember to do not nest DrawerLayout in another activity layout between other components.
Upvotes: 2
Reputation: 1231
The reason your list view is not working is because u placed it in the bottom layer and over it you placed a drawer so the drawer is over the listview and the drawer is set to match_parent
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="marcin.chruscicki.notefication.MainActivity"
android:background="@color/universalBackground_DarkGray">
...
<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"
android:fitsSystemWindows="true"
>
<!-- The main content view -->
<android.support.design.widget.NavigationView
android:layout_width="240dp"
android:layout_height="match_parent"
android:id="@+id/nav"/>
</android.support.v4.widget.DrawerLayout>
...
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/notesListView"
android:stackFromBottom="false"
android:layout_alignParentStart="true"
android:layout_above="@+id/versionTxtView" />
</RelativeLayout>
try to place the list view like this when you make a item in the layout it goes one over another that means the last you place the item will be at the front you need to make the navigation drawer listviw in the fragment layout .Here is a full example how you can dofragment example .hope this will help you.Try to make a fragment for navigation drawer its easy .
Upvotes: 2