Align Custom View To Left Of Navigation Drawer
As you can see the custom layout is at the right and after some research I found that the blank space is reserved for icon and text of item. Is there a way to remove that blank spa
Solution 1:
Change your code according to my , its working . Take RelativeLayout
as parent (only change with your connect_us.xml):
connect_us.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="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF"
android:gravity="left">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/connect_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_launcher"
android:padding="5dp" />
<ImageView
android:id="@+id/connect_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_launcher"
android:padding="5dp"/>
<ImageView
android:id="@+id/connect_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_launcher"
android:padding="5dp"/>
</LinearLayout>
</RelativeLayout>
Second Solution :
In your main_activity.xml (fix the width of the Navigation drawer)
I used here
android.support.design.widget.NavigationView
to android:layout_width="320dp"
I know its not a proper solution to fix layout_width
.
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
And connect_us.xml layout also set the layout_width = "320dp"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="match_parent"
android:background="@color/app_bg_color"
android:orientation="horizontal"
android:gravity="start">
<ImageView
android:id="@+id/connect_youtube"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/youtube_icon"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:padding="5dp" />
<ImageView
android:id="@+id/connect_facebook"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/facebook_icon"
android:padding="5dp"/>
<ImageView
android:id="@+id/connect_twitter"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/twitter_icon"
android:padding="5dp"/>
</LinearLayout>
Solution 2:
Try adding your navigation view and Custom Layout (connect_us) inside a NestedScrollView as below:-
<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">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.NavigationView
android:id="@+id/nav1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:background="@color/bottom_navigation_color"
android:fitsSystemWindows="true"
android:theme="@style/NavigationView"
app:headerLayout="@layout/nav_header"
app:itemBackground="@color/app_bg_color"
app:itemIconTint="@color/text_white"
app:itemTextColor="@color/text_white"
app:menu="@menu/nav_drawer_items" />
<include
android:id="@+id/footer_layout"
layout="@layout/connect_us"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.DrawerLayout>
Also, make sure to disable Nested Scrolling of NavigationView's child as below:-
ViewCompat.setNestedScrollingEnabled(navigationView.getChildAt(0), false);
Solution 3:
I got a solution for this use recyclerview
and inside your navigation view and add your views to recyclerview
and create your adapter :
<?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="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/my"
layout="@layout/nav_header_main" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvNavMenu"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="7"
android:overScrollMode="never" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Post a Comment for "Align Custom View To Left Of Navigation Drawer"