SwipeRefreshLayout (v4) with Toolbar hide the Listview - android

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

Related

overlapping a screen in android

In the below layout i have a text view named as scanning device.In that am displaying a device name But my device list was displaying above the screen .
can any one please help me how to scroll view should be inside the device list.while scrolling the screen it was displaying the list of the devices but it is displaying above the screen.
want to display inside a screen.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="#string/back"
android:textAllCaps="true"
android:textColor="#color/white"
android:visibility="invisible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:padding="10dp"
android:textStyle="bold"
android:text="#string/lamp_list"
android:textAllCaps="true"
android:textColor="#color/white" />
<TextView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableRight="#drawable/refresh"
android:gravity="right"
android:padding="10dp"
android:textAllCaps="true"
android:textColor="#color/white" />
<ProgressBar
android:id="#+id/scanningProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/baground"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="#string/start_discovery"
android:textColor="#color/white"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In the below layout connect textview was coming out of the layout.
device_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="6dp"
android:src="#drawable/lamp" />
<TextView
android:id="#+id/deviceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:textColor="#color/white"
android:textSize="17sp"
tools:text="Solar Enviro SSL 2016" />
<TextView
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:background="#drawable/rounded_red_view"
android:text="#string/connect"
android:paddingBottom="1dp"
android:paddingTop=".2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textColor="#color/white"
android:textSize="17sp" />
</LinearLayout>
change this things..
used both wrap_content. i hope you also remove default action bar.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<TextView
android:id="#+id/scan_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="18dp"
android:gravity="center"
android:visibility="gone"
tools:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/deviceListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Instead of CoordinatorLayout use linear layout.
if u r a beginner start coding with linear layout. It is easy to understand.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

AppBarLayout leaves previous expanded view spacing after fragment change

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;

Collapsing Toolbar hide when scroll up and show when scroll Down

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 !

RecyclerView cutting off sides of CardView

I have a RecyclerView that programmatically inflates CardViews. The left side of the card is getting cut off and they are not centered. If you need any more code posted, I would be happy to do so.
Here is some helpful code:
Activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".Activity.ClassRoster"
tools:showIn="#layout/activity_class_roster"
android:orientation="vertical"
android:gravity="center">
<android.support.v7.widget.RecyclerView android:id="#+id/roster_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp"
android:clipToPadding="false"
android:scrollbars="vertical"
android:gravity="center"/>
</LinearLayout>
Cards being inflated:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card_linlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card"
android:layout_width="#dimen/student_card_width"
android:layout_height="#dimen/student_card_height"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
android:clickable="true"
android:foreground="#drawable/custom_bg"
card_view:cardCornerRadius="#dimen/student_card_radius"
card_view:cardElevation="#dimen/student_card_elevation">
<RelativeLayout android:id="#+id/card_layout"
android:background="#color/a"
android:layout_width="match_parent"
android:layout_height="160dp">
<TextView android:id="#+id/student_name"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textColor="#android:color/white"
android:text="TS"
android:textSize="#dimen/student_card_text_size"
android:gravity="center"
android:textIsSelectable="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_delete_black_24dp"/>
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
</android.support.v7.widget.Toolbar>
</android.support.v7.widget.CardView>
</LinearLayout>
To make your text center, change TextView width to match_parent
<RelativeLayout android:id="#+id/card_layout"
>
<TextView android:id="#+id/student_name"
android:layout_width="match_parent" // before it is wrap_content
... />
</RelativeLayout>
Make your bottom center correct
// I organize the flow of your layout from left-to-right
// Before it is right-to-left
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_delete_black_24dp"/>
</android.support.v7.widget.Toolbar>
Hope this help
Try to remove the top-level LinearLayout of your item xml like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/student_card"
android:layout_width="#dimen/student_card_width"
android:layout_height="#dimen/student_card_height"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
android:clickable="true"
android:foreground="#drawable/custom_bg"
card_view:cardCornerRadius="#dimen/student_card_radius"
card_view:cardElevation="#dimen/student_card_elevation">
<RelativeLayout android:id="#+id/card_layout"
android:background="#color/a"
android:layout_width="match_parent"
android:layout_height="160dp">
<TextView android:id="#+id/student_name"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textColor="#android:color/white"
android:text="TS"
android:textSize="#dimen/student_card_text_size"
android:gravity="center"
android:textIsSelectable="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<android.support.v7.widget.Toolbar android:id="#+id/card_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom">
<ImageView android:id="#+id/student_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="25dp"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_delete_black_24dp"/>
<ImageView android:id="#+id/student_absent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="25dp"
android:src="#drawable/ic_change_history_black_24dp"/>
</android.support.v7.widget.Toolbar>
</android.support.v7.widget.CardView>

How to right Align the image on the Toolbar in Android

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");

Categories

Resources