I am using ToolBar in my activity. I want to right align the profile picture of user.
I have used android:layout_alignParentRight="true" but it is not working.
1. XML
<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">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Top Toolbar-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#3f5e7e"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
<com.sevenhorse.View.CircularImageView
android:id="#+id/profile"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_alignParentRight="true"
android:foregroundGravity="right"
/>
<!-- android:layout_centerVertical="true"-->
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar_top"
android:background="#fbae38"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabGravity="fill"
app:tabMode="fixed"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/reltv_footer"
android:layout_below="#+id/tab_layout"></android.support.v4.view.ViewPager>
<RelativeLayout
android:id="#+id/reltv_footer"
android:layout_width="match_parent"
android:layout_height="50sp"
android:layout_alignParentBottom="true"
android:background="#2b4d72">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="20sp" />
<ImageView
android:id="#+id/img_Profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#2b4d72"
android:padding="15sp"
android:src="#drawable/more_option" />
<View
android:id="#+id/img_view"
android:layout_width="3sp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/img_Profile"
android:background="#335980" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/img_view"
android:background="#2b4d72"
android:gravity="left"
android:orientation="horizontal">
<ImageView
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#203b58"
android:padding="15sp"
android:src="#drawable/home" />
<View
android:layout_width="2sp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/img_Profile"
android:background="#203b58" />
<ImageView
android:id="#+id/friendrequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="15sp"
android:src="#drawable/friend_req" />
<View
android:layout_width="2sp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/img_Profile"
android:background="#203b58" />
<ImageView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="15sp"
android:src="#drawable/meg" />
<View
android:layout_width="2sp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/img_Profile"
android:background="#203b58" />
<ImageView
android:id="#+id/notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="15sp"
android:src="#drawable/footer_notification" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/reltv_Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/reltv_footer"
android:layout_alignParentRight="true"
android:background="#ffffff"
android:visibility="gone">
<ListView
android:id="#+id/listviewmoroption"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:divider="#6d6d6d"
android:dividerHeight="1sp"></ListView>
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#android:color/white"
android:choiceMode="singleChoice"
android:orientation="vertical">
<include layout="#layout/cust_rightnavigationdrawer" />
</LinearLayout>
2.ScreenShot
How can i align the image to the right end of the toolbar?
You can only use android:layout_alignParentRight="true" inside a RelativeLayout, and Toolbar is a simple ViewGroup. To achieve the alignment, add a RelativeLayout inside the Toolbar and move the ImageView inside it:
<android.support.v7.widget.Toolbar
...
>
<RelativeLayout
...>
<com.sevenhorse.View.CircularImageView
...
android:layout_alignParentRight="true"
...
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Try to give android:layout_gravity="right"
<com.sevenhorse.View.CircularImageView
android:id="#+id/profile"
android:layout_width="40sp"
android:layout_height="40sp"
android:foregroundGravity="right"
android:layout_gravity="right"
android:layout_alignParentRight="true"
/>
Add RelativeLayout in Toolbar and then use android:layout_alignParentRight="true" with CircularImageView
<!--Top Toolbar-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#3f5e7e"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.sevenhorse.View.CircularImageView
android:id="#+id/profile"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_alignParentRight="true"
android:foregroundGravity="right"
/>
<!-- android:layout_centerVertical="true"-->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
inside you can put any Layout like Linear Layout,Frame Layout,it will work fine
that layout width should be match parent
The accepted answer only works if layout_width="match_parent" ,but this action also overshadows/hides the toolbar title.
The only way to show both the Image and the Toolbar title is by having the relative layout's width as a fixed length and that is not ideal for most people. Even then, the relative layout does not align to right.
My Workaround
Have the relative layout width as layout_width="match_parent" ( This hides the toolbar title )and then add a plain textview inside of it with alignParentStart="true"
Then in the main activity, replace toolbar.setTitle("my_title") , with textView.setText("my_title")
i.e
<androidx.appcompat.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/AppTheme.AppBarOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout android:id="#+id/toolbar_item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--The Title Bar -->
<TextView android:id="#+id/title_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/heading"
android:textColor="#color/white"
android:layout_alignParentStart="true" />
<!--The Inbox-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginEnd="#dimen/layout_margin"
android:layout_toLeftOf="#+id/switchhouse_panel">
<ImageView android:id="#+id/house_admin_messages"
android:layout_width="25dp"
android:layout_height="25dp"
android:cropToPadding="true"
android:scaleType="centerCrop"
app:srcCompat="#drawable/ic_email_white_24dp"
android:layout_alignParentTop="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="#drawable/circle_custom"
android:backgroundTint="#color/green"
android:cropToPadding="true"
android:layout_marginStart="20dp"/>
</RelativeLayout>
<!--The Switch-->
<RelativeLayout android:id="#+id/switchhouse_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:layout_marginStart="#dimen/layout_margin"
android:layout_alignParentRight="true">
<ImageView android:id="#+id/house_cover_thumbnail"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/circle_custom"
android:cropToPadding="true"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/circle_custom"
android:padding="3dp"
app:srcCompat="#drawable/ic_cached_black_24dp"
android:cropToPadding="true"
android:layout_marginStart="20dp"/>
</RelativeLayout>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
In Main Activity
TextView title_bar = findViewById(R.id.title_bar);
title_bar.setText("Manage Property");
Related
I keep getting an error that my LinearLayout isn't allowed in my RelativeLayout object.
I am trying to create a multi-filter search bar. This LinearLayout is meant to hold different elements in the search bar. Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#212121"
android:minHeight="?attr/actionBarSize">
<TextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/app_name"
android:textColor="#FFF" />
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:id="#+id/view_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#50000000"
android:clickable="true"
android:visibility="invisible">
<ProgressBar
android:id="#+id/marker_progress"
style="?android:attr/progressBarStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="gone" />
</RelativeLayout>
<ListView
android:id="#+id/listContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clipToPadding="false"
android:divider="#fff"
android:paddingTop="56dp"
android:visibility="gone" />
<androidx.appcompat.widget.CardView
android:id="#+id/card_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:visibility="invisible"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linearLayout_search"
android:layout_width="match_parent"
android:layout_height="48dp">
<ImageView
android:id="#+id/image_search_back"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:padding="12dp"
android:src="#mipmap/ic_arrow_back" />
<EditText
android:id="#+id/edit_text_search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#fff"
android:focusable="true"
android:gravity="center_vertical"
android:hint="#string/search_restaurants_and_cuisines"
android:imeOptions="actionSearch"
android:inputType="textCapWords"
android:maxLines="1"
android:paddingLeft="12dp"
android:paddingRight="8dp" />
</LinearLayout>
<View
android:id="#+id/line_divider"
android:layout_width="match_parent"
android:layout_height=".5dp"
android:layout_below="#+id/linearLayout_search"
android:background="#eee" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/line_divider"
android:divider="#FFFFFF" />
</RelativeLayout>
</androidx.appcompat.widget.CardView>
<TextView
android:id="#+id/txtNoResultsFound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="#dimen/activity_horizontal_margin"
android:text="#string/no_results_found" />
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:layout_marginBottom="#dimen/corners_small_value"
android:layout_marginLeft="#dimen/corners_small_value"
android:layout_marginRight="#dimen/corners_small_value">
</ListView>
<View
android:id="#+id/toolbar_shadow"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="#+id/toolbar"
android:background="#drawable/toolbar_shadow" />
</RelativeLayout>
Why is this happening? I made sure it is in the updated androidx CardView, so not sure why LinearLayout is still not allowed to be in the RelativeLayout inside CardView.
It looks like you have a typo in your CardView tag:
<androidx.appcompat.widget.CardView
That should look like this instead:
<androidx.cardview.widget.CardView ...
(Replace .appcompat. with .cardview.).
I have the following layout :
<?xml version="1.0" encoding="utf-8"?>
<nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScaleOpen="0.87"
app:marginFactor="0.7">
<nl.psdcompany.duonavigationdrawer.views.DuoMenuView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_menu_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="#string/tag_menu"
app:footer="#layout/drawer_footer"
app:header="#layout/drawer_header" />
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="#string/tag_content"
android:translationZ="8dp">
<include layout="#layout/layout_toolbar" />
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout>
The include layout is
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:translationZ="4dp"
app:contentScrim="#color/colorPrimary"
app:layout_scrollFlags="exitUntilCollapsed|snap"
app:scrimAnimationDuration="250">
<!--
Toolbar Collapsing Layout
-->
<LinearLayout
android:id="#+id/collapsing_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="56dp"
android:orientation="vertical"
android:visibility="visible"
app:layout_collapseMode="parallax">
<TextView
android:id="#+id/collapsing_toolbar_title"
fontPath="#string/font_sf_ui_display_black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textColor="#color/white"
android:textSize="24sp"
android:visibility="visible" />
<TextView
android:id="#+id/collapsing_toolbar_secondary_title"
fontPath="#string/font_sf_ui_display_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:textColor="#color/dark_red"
android:textSize="#dimen/text_small"
android:visibility="visible" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<RelativeLayout
android:id="#+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingEnd="#dimen/margin_medium"
android:paddingStart="#dimen/margin_medium">
<!--
Toolbar TOP Layout
-->
<RelativeLayout
android:id="#+id/toolbar_top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?attr/actionBarSize">
<RelativeLayout
android:id="#+id/default_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:visibility="visible">
<!-- Starting icons container -->
<FrameLayout
android:id="#+id/toolbar_left_icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginEnd="#dimen/margin_small">
<ImageView
android:id="#+id/toolbar_hamburger"
android:layout_width="#dimen/toolbar_icon_size"
android:layout_height="#dimen/toolbar_icon_size"
android:layout_gravity="center"
android:tint="#color/white"
android:visibility="gone"
app:srcCompat="#drawable/ic_burger_menu_white" />
<ImageView
android:id="#+id/toolbar_start_icon"
android:layout_width="#dimen/toolbar_icon_size"
android:layout_height="#dimen/toolbar_icon_size"
android:layout_gravity="center"
android:tint="#android:color/white"
android:visibility="gone"
app:srcCompat="#drawable/ic_back_button_white" />
<TextView
android:id="#+id/toolbar_start_text_icon"
fontPath="#string/font_sf_ui_display_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Cancel"
android:textColor="#color/dark_red"
android:textSize="#dimen/text_medium"
android:visibility="gone"
app:srcCompat="#drawable/ic_back_button_white" />
</FrameLayout>
<!-- Step Progress Bar -->
<FrameLayout
android:id="#+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#id/toolbar_left_icon_container"
android:visibility="gone"/>
<!-- Main title centered in the toolbar -->
<LinearLayout
android:id="#+id/toolbar_title_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/toolbar_main_title"
fontPath="#string/font_sf_ui_display_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:text="View Offer"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="15sp"
android:visibility="gone" />
<TextView
android:id="#+id/toolbar_secondary_title"
fontPath="#string/font_sf_ui_display_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:text="last visit on 15-03"
android:textColor="#color/dark_red"
android:textSize="#dimen/text_small"
android:visibility="gone" />
</LinearLayout>
<!-- Secondary end icon -->
<ImageView
android:id="#+id/toolbar_secondary_end_icon"
android:layout_width="#dimen/toolbar_icon_size"
android:layout_height="#dimen/toolbar_icon_size"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginEnd="#dimen/margin_small"
android:layout_toStartOf="#+id/toolbar_end_icon_container"
android:visibility="gone"
app:srcCompat="#drawable/ic_share_white" />
<!-- Primary end icon container-->
<FrameLayout
android:id="#+id/toolbar_end_icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<ImageView
android:id="#+id/toolbar_primary_end_icon"
android:layout_width="#dimen/toolbar_icon_size"
android:layout_height="#dimen/toolbar_icon_size"
android:layout_gravity="center"
android:visibility="gone"
app:srcCompat="#drawable/ic_share_white" />
<!-- Badge counter container -->
<FrameLayout
android:id="#+id/toolbar_badge_counter_container"
android:layout_width="28dp"
android:layout_height="28dp"
android:visibility="gone">
<ImageView
android:id="#+id/toolbar_badge_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="4dp"
android:visibility="gone"
app:srcCompat="#drawable/ic_bell_notifications" />
<TextView
android:id="#+id/toolbar_badge_counter"
fontPath="#string/font_sf_ui_display_medium"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="end"
android:background="#drawable/circle_blue"
android:gravity="center"
android:text="3"
android:textColor="#color/white"
android:textSize="9sp"
android:visibility="gone" />
</FrameLayout>
<TextView
android:id="#+id/toolbar_right_text_icon"
fontPath="#string/font_sf_ui_display_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/dark_red"
android:textSize="#dimen/text_medium"
android:visibility="gone" />
</FrameLayout>
<Button
android:id="#+id/change_postal_code_button"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/margin_small"
android:layout_toLeftOf="#+id/toolbar_end_icon_container"
android:background="#drawable/rounded_background_blue"
android:drawablePadding="#dimen/margin_small"
android:drawableStart="#drawable/ic_navigation_white"
android:minHeight="0dp"
android:paddingBottom="#dimen/margin_small"
android:paddingLeft="#dimen/margin_small_medium"
android:paddingRight="#dimen/margin_small_medium"
android:paddingTop="#dimen/margin_small"
android:text="1234 AA, Amsterdam"
android:textAllCaps="false"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
<!--
Toolbar BOTTOM Layout
-->
<LinearLayout
android:id="#+id/toolbar_bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar_top_container"
android:orientation="vertical"
android:paddingBottom="#dimen/margin_medium"
android:visibility="gone">
<TextView
android:id="#+id/toolbar_bottom_title"
fontPath="#string/font_sf_ui_display_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="View Offer"
android:textColor="#color/white"
android:textSize="24sp"
android:visibility="gone" />
<TextView
android:id="#+id/toolbar_bottom_secondary_title"
fontPath="#string/font_sf_ui_display_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-3dp"
android:text="last visit on 15-04"
android:textColor="#color/dark_red"
android:textSize="#dimen/text_small"
android:visibility="gone" />
<include
android:id="#+id/search_toolbar"
layout="#layout/layout_search_offers" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
It consists of an AppBarLayout with an CollapsingToolbarLayout which has as the first child a Linear that's acting as the collapse layout and a Toolbar layout which holds the top bar and a static bottom one when I need a bottom non collapsing toolbar.
The collapsing works great, I can set my ToolBar to have only the top layout or only the bottom but when I change the visibility of items to Gone the AppBarLayout(or the CollapsingToolbarLayout) doesn't resize and keeps the spacing.
Example image :
After fragment change (I set views to Gone to reset the layouts)
Thank you for your time;
In our chat app new message start first. For see old message user scroll up. For this we set reverseLayout true.
Ex: LayoutManager reverse so 0 position is botttom. when user scroll for old message suppose position is 10 . so i want to hide toolbar.when user go below from 10 position to 9 position i want to show toolbar.
LinearLayoutManager linearLayoutManager = new WrapContentLinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
linearLayoutManager.setReverseLayout(true);
We want to hide collapsing toolbar when user scroll up for fetch old message and show collapsing toolbar when user scroll down.
Any hints on how to achieve this?
XML Code as below :
<?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/rlMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/whole_background_color"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBackgroundWall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rlChatMessageSendView">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<include
android:id="#+id/rlZoneDetail"
layout="#layout/include_layout_zone_option" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="com.gochat.uIUtil.FixScrollingFooterBehavior">
<RelativeLayout
android:id="#+id/rel_root_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rlChat"
android:paddingBottom="#dimen/margin_five">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewChat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none"
android:visibility="visible"
tools:listitem="#layout/chat_adapter_message_layout" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:theme="#style/AppTheme.ProgressBarColor"
android:visibility="gone" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvFollow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="#dimen/padding_five"
android:layout_marginTop="#dimen/padding_ten"
android:background="#drawable/background_login_signup_small_radius"
android:gravity="center"
android:maxLines="1"
android:paddingBottom="#dimen/padding_five"
android:paddingLeft="#dimen/padding_twenty"
android:paddingRight="#dimen/padding_twenty"
android:paddingTop="#dimen/padding_five"
android:singleLine="true"
android:text="#string/start_follow"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="#dimen/text_size_fifteen"
android:visibility="gone" />
<LinearLayout
android:id="#+id/llAnnounce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/recyclerViewChat"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/padding_five"
android:layout_marginRight="#dimen/padding_five"
android:layout_marginTop="#dimen/padding_five"
android:background="#drawable/background_login_signup_small_radius"
android:gravity="center"
android:visibility="gone">
<ImageView
android:layout_width="#dimen/padding_thirteen"
android:layout_height="#dimen/padding_thirteen"
android:layout_marginLeft="#dimen/margin_seven"
android:layout_marginStart="#dimen/margin_seven"
android:src="#drawable/iv_white_shout" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvAnnouncement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_twenty"
android:layout_marginLeft="#dimen/margin_ten"
android:layout_marginRight="#dimen/margin_twenty"
android:layout_marginStart="#dimen/margin_ten"
android:gravity="center"
android:maxLines="1"
android:paddingBottom="#dimen/padding_five"
android:paddingTop="#dimen/padding_five"
android:singleLine="true"
android:text="#string/announce_text"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="#dimen/text_size_thirteen"
android:visibility="visible" />
<ImageView
android:layout_width="#dimen/padding_thirteen"
android:layout_height="#dimen/padding_thirteen"
android:layout_marginEnd="#dimen/margin_seven"
android:layout_marginRight="#dimen/margin_seven"
android:src="#drawable/iv_white_send" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/rlChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#color/bg_bottombar"
android:orientation="vertical"
android:visibility="visible"
app:layout_behavior="com.gochat.uIUtil.FixScrollingFooterBehavior">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/onedp"
android:background="#color/create_zone_divider_color_whatsapp" />
<RelativeLayout
android:id="#+id/rl_send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bottom_tab"
android:padding="#dimen/padding_seven"
android:visibility="visible">
<RelativeLayout
android:id="#+id/rlAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:paddingBottom="#dimen/padding_ten"
android:paddingRight="#dimen/margin_eight"
android:paddingTop="#dimen/padding_ten">
<ImageView
android:id="#+id/ivAdd"
android:layout_width="#dimen/margin_twenty"
android:layout_height="#dimen/margin_twenty"
android:layout_centerVertical="true"
android:src="#drawable/iv_add_blue" />
</RelativeLayout>
<ImageView
android:id="#+id/ivFullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/iv_add_blue"
android:visibility="gone" />
<ImageView
android:id="#+id/ivMenuOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rel_message"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/margin_twenty"
android:layout_marginRight="#dimen/margin_twenty"
android:layout_toLeftOf="#+id/ivFullscreen"
android:layout_toStartOf="#+id/ivFullscreen"
android:src="#drawable/iv_menu_grid"
android:visibility="gone" />
<TextView
android:id="#+id/tv_Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="TITLE"
android:textStyle="bold"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/rel_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/rlAdd"
android:layout_toLeftOf="#+id/iv_send"
android:layout_toRightOf="#+id/rlAdd"
android:layout_toStartOf="#+id/iv_send"
android:background="#drawable/chat_send_message_background"
android:visibility="visible">
<RelativeLayout
android:id="#+id/rl_chat_send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<EditText
android:id="#+id/et_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_ten"
android:layout_marginLeft="#dimen/margin_ten"
android:layout_marginRight="#dimen/margin_ten"
android:layout_marginStart="#dimen/margin_ten"
android:background="#null"
android:hint="#string/type_messsage"
android:inputType="textMultiLine"
android:maxLines="4"
android:padding="#dimen/padding_eight"
android:textColorHint="#color/hint_text_color"
android:textSize="#dimen/text_size_fifteen"
tools:text="zxnihxkbdfcdaaa" />
</RelativeLayout>
</RelativeLayout>
<ImageView
android:id="#+id/iv_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/margin_five"
android:src="#drawable/iv_send_message_light"
android:visibility="invisible" />
<ImageView
android:id="#+id/iv_record"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/margin_five"
android:src="#drawable/iv_audio_record"
android:visibility="visible" />
</RelativeLayout>
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#color/white"
android:padding="#dimen/padding_fifteen"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<RelativeLayout
android:id="#+id/rlChatMessageSendView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/llSpectatorZone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="#dimen/margin_ten"
android:background="#color/white"
android:orientation="horizontal"
android:padding="#dimen/padding_ten"
android:visibility="gone">
<TextView
android:id="#+id/tvSpectatorZone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/you_can_only_view_this_zone"
android:textColor="#color/unselected_item_color"
android:textSize="#dimen/text_size_seventeen" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Please try below link. It may solve your problem.
http://xmodulo.com/hide-show-toolbar-scrolling-android.html
Thanks !
Is it possible to set scrollbar below a toolbar in Android? I am trying out the scrollbarView I have toolbar attached to my Layout something like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
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="#color/layoutcolor_background"
android:orientation="vertical"
tools:ignore="ContentDescription,RtlHardcoded,NestedWeights">
<include
android:id="#+id/toolbar"
layout="#layout/main_toolbar" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#drawable/toolbar_dropshadow" />
<LinearLayout
android:id="#+id/aandcID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_weight=".50"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/alayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight=".50"
android:background="#color/layoutbackgroudforrow"
android:gravity="center">
<ImageView
android:id="#+id/aimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:paddingBottom="3dp"
android:paddingTop="5dp"
android:src="#drawable/acc" />
<TextView
android:id="#+id/aType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/aimage"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:gravity="center"
android:paddingLeft="2dp"
android:singleLine="true"
android:text="Deposit"
android:textColor="#color/blackText"
android:textSize="18sp"
android:textStyle="bold"
tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />
<TextView
android:id="#+id/anumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/aType"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:gravity="center"
android:paddingLeft="2dp"
android:singleLine="true"
android:text="12345678901234567890"
android:textColor="#color/blackText"
android:textSize="18sp"
tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />
<ImageView
android:id="#+id/rupeeIcon"
android:layout_width="12dp"
android:layout_height="14dp"
android:layout_below="#+id/anumber"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:layout_toLeftOf="#+id/accatext"
android:background="#drawable/rupees_symbol"
android:paddingBottom="2dp"
android:visibility="visible"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/accatext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/anumber"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:gravity="center"
android:paddingLeft="2dp"
android:singleLine="true"
android:text="09876543210987654321"
android:textColor="#color/numbertext"
android:textSize="16sp"
tools:ignore="RtlSymmetry,RtlHardcoded,HardcodedText" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/footer_band" />
</LinearLayout>
</ScrollView>
With the above code.. Toolbar is also scrolled and hence it get cut too. Is there a way freeze toolbar and then scroll other views.
It would be great if somebody could guide me?
Thanks!
Just do something like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Rest of your content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
Just put the Toolbar above the ScrollView, and then, add then add the layout_below parameter in the ScrollView, so you make sure it appears under the Toolbar.
It definitely works.
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:ads = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
app:layout_behavior = "#string/appbar_scrolling_view_behavior"
tools:showIn = "#layout/category_layout">
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
i have a layout with swipeaRefreshLayout and a Toolbar(Both from v4 and v7 using v-21), but when i start the app the listview its hide, i only can see the toolbar like a actionbar.
This is my code:
<?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.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_toEndOf="#id/toolbar">
<ListView
android:id="#+id/questionList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/swipe_container"
android:layout_gravity="center_horizontal"
android:layout_toEndOf="#id/swipe_container"
android:background="#686868"
android:visibility="visible" />
<com.shamanland.fab.FloatingActionButton
android:id="#+id/btnNew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="50dp"
android:layout_marginRight="32dp" />
<LinearLayout
android:id="#+id/emptyData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#686868"
android:clickable="true"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="4dp"
android:text="No hay elementos disponibles"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="4dp"
android:src="#android:drawable/ic_dialog_email" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
SwipeRefreshLayout can only have a single child view, wrap it's content in a linearlayout. That should solve your issue