Main activity layout (removed the irrelevant elements):
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
<RelativeLayout
android:id="#+id/layout_relative_in_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black" >
// some more elements ...
</RelativeLayout>
<ListView
android:id="#+id/drawer_main"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#80000000"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" />
</android.support.v4.widget.DrawerLayout>
drawer_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerItemTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#android:color/white" >
</TextView>
The list items are aligned to the center horizontally now, but not vertically.
What should i modify to center them vertically?
Change your drawer item to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/frag1_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
then try, it is working for me.
<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.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:background="#ffffff" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#eeeeee" >
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333333"
android:choiceMode="singleChoice"
android:divider="#android:color/darker_gray"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|left"
android:padding="5dp"
android:text="Medium Text"
android:textColor="#FB9200" />
</LinearLayout>
drawer_item.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="a" />
</RelativeLayout>
Probably you should change the gravity of items to:
android:gravity="center|center_vertical"
Related
I was implementing a swipe to refresh the Relative layout inside a drawer layout
.It was all working fine before implementing the swipe to refresh once added it , the recyclerview element is not getting displayed
Am adding my layout below
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.pratheesh.madfest_sample.Mainpage"
android:background="#color/feed_bg"
android:id="#+id/drawerlayout"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/activity_madfext__toolbar"
android:id="#+id/mainpage_toolbar"
>
</include>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="80dp"
tools:context="com.example.pratheesh.madfest_sample.CardRow"
android:background="#drawable/feed_background"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:id="#+id/mainpage_add"
android:layout_below="#+id/mainpage_toolbar"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/feed_item_padding_top_bottom"
android:paddingTop="#dimen/feed_item_padding_top_bottom"
android:paddingLeft="#dimen/feed_item_padding_left_right"
android:paddingRight="#dimen/feed_item_padding_left_right" >
<com.example.pratheesh.madfest_sample.AspectRatioImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/images"
android:id="#+id/mainpage_imageview_profile1"
android:scaleType="fitCenter"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to add Feeds"
android:id="#+id/mainpage_feeds"
android:textStyle="normal"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/mainpage_imageview_profile1"
android:layout_margin="5dp"
android:layout_marginTop="5dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:layout_marginTop="0dp"
android:layout_below="#+id/mainpage_add"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</FrameLayout>
</ScrollView>
<android.support.design.widget.NavigationView
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/navigationview"
app:menu="#menu/drawer"
app:headerLayout="#layout/activity_navigation_header"
app:itemTextAppearance="#style/NavigationDrawerStyle"
>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
I have a menu with fragment (the screen of each menu's item). I need to align this items in center vertically.
There's my code:
activity_maps.xml (the screen of 'map' item)
<?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">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/map"
tools:context=".HomeFragment"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
and the menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:background="#drawable/list_selector">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="200dp"
android:contentDescription="#string/desc_list_item_icon"
android:src="#drawable/ic_home"
android:gravity="center_vertical"
android:layout_centerVertical="true" />
</RelativeLayout>
There's the activity_main with the menu which has some menu_itens.xml inside a listView
<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_centerVertical="true"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
Edit: print link
http://s12.postimg.org/3ysbeaarx/Screenshot_2015_03_06_10_35_53.png
you can use this LinearLayout instead of ListView
<LinearLayout
android:layout_width="240dp"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
or u can redesign as u like with any layout
I have created a navigation drawer having a listview with icon and text. Now, I want to add a title above it and also another below it. Below are two xml I have used:
<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">
<!-- <fragment
android:id="#+id/badMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" /> -->
<FrameLayout
android:id="#+id/testFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:background="#color/list_background"/>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
</RelativeLayout>
And:
<?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="40dp"
android:background="#drawable/list_selector">
<LinearLayout
android:id="#+id/itemLayout"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:layout_marginTop="0dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="55dp"
>
<ImageView
android:id="#+id/drawerIcon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="#string/desc_list_item_icon"
android:src="#drawable/high"
android:layout_centerVertical="true"
android:gravity="center" />
<TextView
android:id="#+id/drawerTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/drawerIcon"
android:gravity="center"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:layout_centerVertical="true"
android:text="#string/drawerlistTitle"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/list_item_title" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#DADADC"
></View>
</LinearLayout>
</RelativeLayout>
Any ideas on how to add a titles in this?
It's simple actually :-)
Instead of using a ListView as your drawer, you can wrap the ListView in a RelativeLayout for instance like this:
<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" >
<FrameLayout
android:id="#+id/testFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- Listview to display slider menu -->
<RelativeLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title" />
<ListView
android:id="#+id/list_slidermenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titleTextView"
android:layout_above="#+id/titleUnderListView"
android:layout_gravity="start"
android:background="#color/list_background"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector" />
<TextView
android:id="#+id/titleUnderListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="SubTitle" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
</RelativeLayout>
You can put whatever you like as the layout for the NavigationDrawer - the sky is the limit :-)
Another solution could be to add a header and footer to your current ListView, but then it wouldn't be fixed on top or the bottom.
i want to add icons at the action bar , in this layout
i have 2 layout , first one which hold ExpandableListView and second for details fragment ,
how can i do something like that ??
this is the main activity
<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" />
<ExpandableListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:cacheColorHint="#00000000"
android:childDivider="#drawable/child_separator"
android:dividerHeight="0dp"
android:layout_gravity="right"
/>
</android.support.v4.widget.DrawerLayout>
Details Fragment
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLyt"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dip"
android:text="Defaulyyyyyyyyt Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/bottomBar"
android:orientation="horizontal"
android:background="?android:attr/dividerVertical"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/botton_matn"
android:background="?android:attr/selectableItemBackground"
android:text="المتون"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="#+id/botton_rawe"
android:background="?android:attr/selectableItemBackground"
android:text="الراوي"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
</RelativeLayout>
You may try it with ActionBarSherlock. It is more simple.
I try to put my Drawer Navigation above my layout/include_pub" and listViews.
I would like my Navigation Drawer be just below my id "header".
With this XML, nothing appear and I don't know why ?
I have a white view just below my header.
Thanks for advance for yours answers
<?xml version="1.0" encoding="utf-8"?>
<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/include_splash" />
<LinearLayout
android:id="#+id/l_l_tout_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center_vertical" >
<ImageButton
android:id="#+id/i_b_menu_accueil"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/i_v_logo_accueil"
android:layout_width="40dip"
android:layout_height="40dip" />
<TextView
android:id="#+id/t_w_rubrique_accueil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton
android:id="#+id/i_b_reload_accueil"
android:layout_width="35dip"
android:layout_height="35dip" />
</LinearLayout>
</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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/include_pub" />
<LinearLayout
android:id="#+id/l_l_articles_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/l_v_articles_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="#+id/r_l_videos_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/l_v_videos_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/l_l_evenements_accueil"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/l_v_evenements_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/l_l_magazines_accueil"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/l_v_magazines_accueil"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#color/line" >
<TextView
android:id="#+id/teeeeeext"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<!-- The navigation drawer -->
<ListView
android:id="#+id/left_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="15sp" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</LinearLayout>