Add Profile Photo and User Name in Slider using Navigation Drawer - android

I am using Navigation Drawer Pager Sliding Tab Strip. It is showing menus in Slider. Now, I want to add Profile Photo and User Name in Slider. I have tried adding LinearLayout but It is giving ClassCastException.
Source : https://github.com/Balaji-K13/Navigation-drawer-page-sliding-tab-strip
activity.xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<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/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/lightish"
android:choiceMode="singleChoice"
android:divider="#color/blue"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>

Use this layout and you'll get what you need.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frameContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- Left drawer -->
<LinearLayout
android:id="#+id/leftDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:gravity="center" >
<ImageView
android:id="#+id/imgProfilePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/user_placeholder_88"
android:contentDescription="#string/profile_pic" />
<TextView
android:id="#+id/lblUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Medium" />
<ListView
android:id="#+id/drawerList"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#color/drawerListDivider"
android:dividerHeight="0dp"
android:listSelector="#drawable/drawer_list_selector"
android:background="#color/drawerListBackground"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

Related

Layout with Scrollview and drawerlayout

i have a activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<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"
android:background="#drawable/sfondomain" />
<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="#drawable/background" >
</ListView>
but when i run my app, it crash:
Logcat: http://paste.ubuntu.com/9699157/
MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.hide();
}
If I remove the ScrollView, my layout work fine...
I want put the ScrollView for landscape mode
Thank you.. sorry for my english!
I also did the same but when i used linear layout as outer layer, it worked for me.
Means put your scrollview inside a linear layout.
This works for me (tried with sdk 25), no need for LinearLayout, simply put the ScrollView inside the DrawerLayout and make sure the layout parts for the drawer come after the scrollView (otherwise clicking on an item in the drawer list will close the drawer just as if you clicked outside the list in the drawer):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
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="com.example.MyApp.MyActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/backButtonString"
android:id="#+id/button"
android:textColor="#ffffffff"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:onClick="tilbageClicked"
android:background="#drawable/mybutton2"
android:layout_marginBottom="5dp"
android:textAllCaps="false"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/myTextViewString"
android:id="#+id/myTextView"
android:gravity="center"
android:textSize="20dp"
android:layout_below="#id/button"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
<!-- content view -->
<RelativeLayout
android:id="#+id/theContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- navigation drawer -->
<RelativeLayout
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="#+id/theDrawer"
android:layout_gravity="start">
<!-- List of items in drawer -->
<ListView
android:id="#+id/theList"
android:layout_width="60dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
you can put ScrollView inside the DrawerLayout
if you're using an AppBarLayout can add android:layout_marginTop="?actionBarSize"
or the height of your AppBarLayout
Try this it will work.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<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"
android:background="#drawable/sfondomain" />
<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="#drawable/background" >
</ListView>
</LinearLayout>

Multipe List views in Drawer layout in Android

I am using a custom list view to display data in my app, Then i tried to add navigation drawer
Clicks on drawer layout doesnt work. It end up opening the custom list view as it is behind the drawer list view. Drawer list view never gets focus, Even when the drawer is opened
Below is my main activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"/>
</android.support.v4.widget.DrawerLayout>
<ListView
android:id="#+id/listScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="7dp">
</ListView>
</RelativeLayout>
Use this way :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/actionbar" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<include layout="#layout/activity_main" />
<!-- The navigation drawer -->
<include layout="#layout/drawer_layout_right" />
<include layout="#layout/drawer_layout_left" />
</android.support.v4.widget.DrawerLayout>
drawer_layout_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="horizontal" >
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
drawer_layout_left.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical" >
<ListView
android:id="#+id/lv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
<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" >
<include layout="#layout/activity_main" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

customizing Navigation Drawler

Hello i have such layout and i don`t understand how to add static header with photo and text
to Navigation Drawler. Any example? Thanks
like this one
<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">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<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="#9d9d9d"
android:dividerHeight="1dp"
android:background="#252525" />
It's actually not as simple as user665 suggests. If you're going straight off the example provided by Google, you need to let the DrawerLayout know what its content is by changing DrawerLayout.isDrawerOpen and DrawerLayout.closeDrawer to the View your ListView is wrapped in, otherwise you're going to throw a ClassCastException because the LayoutParams won't match up.
So, to make a static header, you could do somehting like:
<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" />
<LinearLayout
android:id="#+id/drawer_content"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
<ImageView
android:id="#android:id/icon"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="#null"
android:scaleType="centerCrop" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Then reference R.id.drawer_content when using the methods I listed above.
After the FrameLayout, the first view will accepted as Navigation Drawer, so you create a layout after FrameLayout, then put your Views inside of it. Here is a example, it is very basic but you will get the point.
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_height="match_parent"
android:layout_width="320dp"
android:orientation="vertical"
android:layout_gravity="start" >
<RelativeLayout
android:id="#+id/NavDrawerInfo"
android:layout_width="320dp"
android:background="#drawable/bg"
android:layout_height="100dp">
<ImageView android:src="#drawable/ic_launcher"
android:id="#+id/userImage"
android:layout_width="200dp"
android:layout_marginRight="200dp"
android:layout_height="100dp"/>
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginLeft="125dp"
android:textSize="20sp"
/>
<TextView
android:id="#+id/userImage"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="125dp"
android:textSize="20sp"
/>
</RelativeLayout>
<ExpandableListView android:id="#+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:childDivider="#color/list_divider"
android:groupIndicator="#drawable/group_indicator"
android:dividerHeight="2dp"
android:gravity="start"
android:background="#f1f1f1"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

How to initially show part of List view on Android

I have a sliding drawer implemented at the bottom of my layout. I want to show one cell as a default. I have been stuck on this for a couple of hours, so any suggestions or ideas will be greatly appreciated.
Here is my XML file:
<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" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<SlidingDrawer
android:id="#+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#color/Red"
android:text="Notification"
android:textColor="#color/White" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/LightGrey">
<ListView
android:id="#+id/notificationList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="#drawable/listselector_yellow"
>
</ListView>
<View
android:id="#+id/dummieView"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#color/LightGrey" >
</View>
</LinearLayout>
</SlidingDrawer>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/White"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#color/LightGrey"
/>
</android.support.v4.widget.DrawerLayout>
You can use ListView's setSelection(int position) method to scroll to a row. See docs here.

Can I add more than a listview to the Navigation Drawer?

Good Day,
I am trying to create a Navigation Drawer with ListView and few more views.
My issue is when i try to click on the other view the click doesn't register
Can you please tell me if i can create a complex view structure as the navigation drawer?
<?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" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/charcoal"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:orientation="vertical"
android:showDividers="middle" >
<ListView
android:id="#+id/home_drawer_lv_accounts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:divider="#color/amazon"
android:dividerHeight="5dp" >
</ListView>
<CheckedTextView
android:id="#+id/home_drawer_cv_banks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/health"
android:focusable="true"
android:gravity="center"
android:text="#string/text_all_banks"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Modify ur xml as follows
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/charcoal"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:orientation="vertical"
android:showDividers="middle" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/home_drawer_lv_accounts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_red_light"
android:choiceMode="singleChoice"
android:divider="#android:color/black"
android:dividerHeight="5dp" >
</ListView>
<CheckedTextView
android:id="#+id/home_drawer_cv_banks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/holo_red_light"
android:focusable="true"
android:text="Some Dummy Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF" />
</RelativeLayout>
</LinearLayout>

Categories

Resources