I had add some view inside Toolbar but there is showing some left padding which I want to remove.
I want to remove those 'Remove this space section.
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swornimlab.swornimlab.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
>
<include
layout="#layout/layout_inside_toolbar" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
View which I want to add inside toolbar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize">
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
>
<TextView
android:text="Hello, Asmin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="left"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"/>
<TextView
android:text="Welcome Home"
android:layout_marginTop="10dp"
android:gravity="left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
</LinearLayout>
<ImageView
android:layout_weight="1"
android:src="#drawable/ic_home_vc"
android:tint="#android:color/white"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView2" />
</LinearLayout>
Just add these two lines in your Toolbar in XML
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
Remove android:layout_gravity="center_vertical" from layout.
And add app:contentInsetStart and app:contentInsetEnd to the Toolbar :
For e.g.
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
So your code looks like this :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
<include
layout="#layout/layout_inside_toolbar" />
</android.support.v7.widget.Toolbar>
layout_inside_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Hello, Asmin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="left"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Large"/>
<TextView
android:text="Welcome Home"
android:layout_marginTop="10dp"
android:gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
</LinearLayout>
<ImageView
android:layout_weight="1"
android:src="#drawable/ic_home_vc"
android:tint="#android:color/white"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView2" />
</LinearLayout>
android:layout_gravity="center_vertical"
This seems to be issue.
Also on another note, i would suggest you to use percentRelativelayout for your layout distribution. Using weight with your linear layout is very expensive
Related
The following code display only 3 of 4 Editext within a ScrollView.
The problem is the last Editext which is overlapping the Button
Why ScrollView isn't working properly?
Or How avoid this overlaps?
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/cl"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bt_next">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
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="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/tv_activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="24sp"
android:text="#string/app_name"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/mysv">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/et_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 1"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 2"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 3"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 4"/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
<Button
android:id="#+id/bt_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Next"/>
This is how looks like at the end of the scroll.
Your problem is not the ScrollView, your problem is the fact that you have the Button floating out by itself outside of the CoordinatorLayout.
If you're trying to get the content above the button, you could try adding alignToTopOf="#id/bt_next (I forget the exact name of the attribute, but you get the idea). Then the Coordinator should sit on top of the button.
If that's not what you're trying to do, post a screenshot of what you're trying to get to and a screenshot of what's broken now.
I've solved using Nestedlayout and a LinearLayout inside.
The key is keep in mind CoordinatorLayout works as a FrameLayout.
The only issue that I find is the toolbar is not hiding when I scroll.
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/cl"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bt_next"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mysv">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
android:id="#+id/tv_activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="24sp"
android:text="#string/app_name"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/mysv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/et_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 1"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 2"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 3"/>
<View android:layout_width="match_parent" android:layout_height="150dp" />
<EditText
android:id="#+id/et_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input 4"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<Button
android:id="#+id/bt_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Next"/>
</RelativeLayout>
I have tried to accomplish something similar to the following layout.
There are a few things to note. The cardview that overlaps the appbar is not supposed to be a part of a nestedscrollview as I have a nestedscrollview in the xml layout. The cardview is positioned correctly but it comes just beneath the appbarlayout.
I just got the solution to this now. I did not give the CardView an elevation value before and that was wrong. I just assumed that making it come last in the CoordinatorLayout should place it on top. It works now. I have added an elevation value. Here is the code -
<xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="250dp"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbarlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/quotes"
android:scaleType="centerCrop"/>
<android.support.v7.widget.Toolbar
android:id="#+id/tool"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginRight="32dp"
android:layout_marginLeft="32dp"
app:layout_anchor="#id/appBar"
app:layout_anchorGravity="bottom|center"
app:cardElevation="#dimen/small_padding"
/>
</android.support.design.widget.CoordinatorLayout>
Try with the following layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#color/colorAccent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_collapseMode="pin">
<ImageView
android:id="#+id/toolbar_logo"
android:src="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
app:cardCornerRadius="8dp"
app:cardElevation="7dp"
android:layout_marginTop="150dp"
android:id="#+id/cardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Photos" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="376" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Followers"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1769"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Following"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="127"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
I want to make logo at center however, it gets set to left & not at center for large screen resolution devices.
Below is my xmls
activity_app_base.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:elevation="1dp">
<include
layout="#layout/app_bar_app_base"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
app_bar_app_base.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="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<include layout="#layout/new_header_toolbar_design"></include>
<include layout="#layout/content_app_base" />
</LinearLayout>
new_header_toolbar_design.xml
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
android:contentInsetStart="0dp"
app:theme="#style/MyToolbarStyle"
android:contentInsetLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetStartWithNavigation="0dp"
app:contentInsetStartWithNavigation="0dp">
<RelativeLayout
android:id="#+id/rl_User_Profile"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView_User_Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:layout_margin="1dp" />
<ImageView
android:id="#+id/imageView_APP_LOGO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignRight="#+id/imageView_User_Image"
android:src="#drawable/header_logo"
android:layout_centerVertical="true"
android:layout_margin="1dp" />
<ImageView
android:id="#+id/imageView_LOGO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignTop="#+id/imageView_APP_LOGO"
android:layout_toRightOf="#+id/imageView_APP_LOGO"
android:layout_toLeftOf="#+id/imageView_Space"
android:layout_alignBottom="#+id/imageView_APP_LOGO"
android:paddingLeft="-65dp"
android:src="#drawable/header_logo"
/>
<ImageView
android:id="#+id/imageView_Space"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Use android:layout_centerInParent="true" for ImageView and remove
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
To align logo at the center, I use this code in the corresponding Activity..
This code may help you
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setLogo(R.drawable.logo_title);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Use Linear Layout and set gravity of Linear Layout to center
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
android:contentInsetStart="0dp"
app:theme="#style/MyToolbarStyle"
android:contentInsetLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetStartWithNavigation="0dp"
app:contentInsetStartWithNavigation="0dp">
<LinearLayout
android:id="#+id/rl_User_Profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<!--Change the size of imageview as per your requirement-->
<ImageView
android:id="#+id/imageView_User_Image"
android:layout_width="30dp"
android:layout_height="30dp"
android:visibility="gone"
android:layout_margin="1dp" />
<ImageView
android:id="#+id/imageView_APP_LOGO"
android:layout_width="30dp"
android:layout_height="30dp"
android:visibility="invisible"
android:src="#drawable/header_logo"
android:layout_margin="1dp" />
<ImageView
android:id="#+id/imageView_LOGO"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/header_logo"
/>
<ImageView
android:id="#+id/imageView_Space"
android:layout_width="30dp"
android:layout_height="30dp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
I'm trying to display "Spaces-Navigation-View" from here https://github.com/armcha/Space-Navigation-View
The problem I'm facing is that the view appears perfectly in simple activity but not in my main activity which contains coordinator layout.
Here is the xml for my main activity and the result is below
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
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_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
tools:context="com.rvnd.bookshare.Strt">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:background="#color/background"
android:paddingTop="#dimen/appbar_padding_top"
app:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/transparent"
app:popupTheme="#style/AppTheme.PopupOverlay">
<TextView
android:text="Book Share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:textSize="27sp"
android:textColor="#color/text"/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabTextAppearance="#android:style/TextAppearance.Widget.TabWidget"
/>
<TextView
android:id="#+id/status"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:elevation="5dp"
android:textColor="#000000"
android:background="#FFD54F"
android:gravity="center"
android:padding="5dp"
android:layout_gravity="top|center"
android:visibility="gone"
android:text="Syncing..."
android:textAppearance="?android:attr/textAppearanceMedium"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<com.luseen.spacenavigation.SpaceNavigationView
android:id="#+id/space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:space_background_color="#color/colorPrimary"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior"/>
/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:visibility="gone"
app:srcCompat="#drawable/booky"/>
</android.support.design.widget.CoordinatorLayout>
Here is the result of it
On the other hand, if I use the same view in a different simpler activity, the view is rendered properly
Here is the code and below it, is how it should actually look like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/activity_history"
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"
tools:context="com.rvnd.bookshare.History"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:background="#color/skyblue"
android:layout_height="40dp">
<TextView
android:text="All your book transfers are recorded here..."
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/status"
android:textColor="#ffffff"
android:gravity="center"
android:layout_weight="1"
android:textSize="13sp"/>
<Button
android:text="Clear history"
android:layout_height="match_parent"
android:id="#+id/clear"
android:textAllCaps="false"
android:layout_width="98dp"
android:textSize="12sp"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rec"/>
<com.luseen.spacenavigation.SpaceNavigationView
android:id="#+id/space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:space_background_color="#color/colorPrimary"
android:background="#color/colorPrimary"
android:layout_gravity="bottom"
app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior"/>
</LinearLayout>
Here is the result :
I've tried everything and It just doesnt display properly, please do help!
Thanks
I have got the following layout code.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#android:color/background_light"
android:fitsSystemWindows="true"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="?attr/homeAsUpIndicator"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:singleLine="true"
android:text="This will run the marquee animation forever"
android:textColor="#color/white"
android:textSize="#dimen/abc_text_size_title_material_toolbar"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.FloatingActionButton
android:id="#+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_menu_share"
app:layout_anchor="#+id/toolbar"
app:layout_anchorGravity="bottom|right|end"
/>
<RelativeLayout
android:layout_width="match_parent"
android:paddingTop="?attr/actionBarSize"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_anchor="#+id/share"
app:layout_anchorGravity="bottom"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:orientation="vertical">
<RadioGroup
android:id="#+id/segment_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dip"
android:layout_marginTop="?attr/actionBarSize"
android:background="#android:color/white"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:checkedButton="#+id/button_one"
android:orientation="horizontal"
android:topRightRadius="0dp">
<RadioButton
android:id="#+id/button_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#null"
android:checked="true"
android:gravity="center"
android:padding="5dp"
android:text=" A "
android:textColor="#drawable/rbtn_text_selector"
/>
<RadioButton
android:id="#+id/button_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector_right"
android:button="#null"
android:gravity="center"
android:padding="5dp"
android:text=" B "
android:textColor="#drawable/rbtn_text_selector"/>
</RadioGroup>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="#+id/play_song_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:visibility="gone"
fab:fab_colorNormal="#color/dark_navy_blue"
fab:fab_colorPressed="#color/light_navy_blue"
fab:fab_icon="#drawable/ic_play_arrow_white"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Im trying to put up the relative layout below the toolbar. I tried adding app:layout_behavior="#string/appbar_scrolling_view_behavior" but still it does not works. I tried adding android:paddingTop and android:marginTop attributes. Adding these attributes works fine in interface but when it comes to real device, the relative layout is still overlapping the toolbar. why so?
You can put your Toolbar layout inside AppBarLayout. Like this
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
// Your Toolar herer
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>