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">
Related
I have a ScrollView in my app and inside it I have created a Linear Layout which contains various elements but the problem is this my buttons on bottom are not displayed properly. They are cut off at bottom. I have used padding and margin but nothing has been happened. Below is my layout
<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:background="#color/light_gray">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginRight="#dimen/dp20"
android:layout_marginTop="#dimen/dp30"
android:orientation="vertical">
<ImageView
android:id="#+id/imgArticleImage"
android:layout_width="match_parent"
android:layout_height="#dimen/dp140"
android:layout_marginBottom="#dimen/dp15"
android:background="#android:color/white"
android:scaleType="fitXY"
android:src="#drawable/banner" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_grey_border_white_bg">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/dp5"
android:text="#string/title"
android:textColor="#android:color/black" />
<android.support.design.widget.TextInputLayout
android:id="#+id/ettxtLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtTitle"
android:padding="#dimen/dp5"
app:counterEnabled="true"
app:counterMaxLength="100"
app:counterTextAppearance="#style/TextLimitStyle">
<android.support.design.widget.TextInputEditText
android:id="#+id/etTitile"
android:layout_width="match_parent"
android:layout_height="#dimen/dp80"
android:background="#android:color/transparent"
android:gravity="top"
android:maxLength="100" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp20"
android:background="#drawable/bg_grey_border_white_bg">
<TextView
android:id="#+id/txtTitleDes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/dp5"
android:text="#string/start_writing"
android:textColor="#android:color/black" />
<android.support.design.widget.TextInputLayout
android:id="#+id/ettxtLayoutDes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtTitleDes"
android:padding="#dimen/dp5"
app:counterEnabled="true"
app:counterMaxLength="1200"
app:counterTextAppearance="#style/TextLimitStyle">
<android.support.design.widget.TextInputEditText
android:id="#+id/etDescription"
android:layout_width="match_parent"
android:layout_height="#dimen/dp140"
android:background="#android:color/transparent"
android:gravity="top"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/layNew"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/dp10"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/btnSave_draft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginRight="#dimen/dp20"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/save_draft"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnPublish_article"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/publish_your_article"
android:textColor="#android:color/white"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/dp10"
android:gravity="center"
android:orientation="horizontal"
>
<Button
android:id="#+id/btnDiscardChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp10"
android:layout_marginRight="#dimen/dp20"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/discard_changes"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnSaveChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="#android:color/holo_blue_light"
android:paddingLeft="#dimen/dp10"
android:paddingRight="#dimen/dp10"
android:text="#string/save_changes"
android:textColor="#android:color/white"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="#+id/pBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
`
Can anyone suggest me what I have missed?
Wrap up another LinearLayout under the ScrollView and give
paddingBottom to the Second child (the second LinearLayout)
so add this to the added linearLayout :-
android:paddingBottom="20dp"
Correct order for padding :-
ScrollView
||
LinearLayout X- X -- > padding Bottom wont be applied
||
LinearLayout with paddingBottom -- > is applicable
Note :- paddingBottom and marginBottom cannot be applied to the immediate child of the ScrollView.
Remove
android:paddingBottom="#dimen/dp10"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
Just add android:paddingBottom="#dimen/dp30" into your LinearLayout:
<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:background="#color/light_gray">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/dp10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/dp20"
android:layout_marginRight="#dimen/dp20"
android:layout_marginTop="#dimen/dp30"
android:orientation="vertical"
android:paddingBottom="#dimen/dp30">
I'm trying to place a linear layout to the right side of a frame layout.
This is the following code in my layout to set them next to each other:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ArmgaSys.ConDoc.Droid.Views.DrawingImageView
android:id="#+id/plan_markup_image"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<SkiaSharp.Views.Android.SKCanvasView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/plan_markup_canvas" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<TextView
android:id="#+id/planMarkupMessage"
android:text="Touch and drag to"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:textColor="#000000"
android:textAlignment="center"
android:gravity="center" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="#888888">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is my text"/>
</LinearLayout>
However, the linear layout does not appear, I believe it is being forced off the screen.
I have tried different combinations of wrap_content and match_parent for various view width/heights but things just aren't working. I have also tried putting the linear layout inside (but at the end of) the frame layout, which worked but it ended up cutting off the edge of the 'ArmgaSys.ConDoc.Droid.Views.DrawingImageView' component.
What do I need to do to get the frame layout and linear layout next to each other so that nothing overlaps or goes off the screen?
Edit
Here is the full layout code
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<include
layout="#layout/widget_toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ArmgaSys.ConDoc.Droid.Views.UIColoredSpinner
android:id="#+id/drawing_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:popupTheme="#style/AppTheme.PopupOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/plan_markup_undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Undo" />
<Button
android:id="#+id/plan_markup_continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continue" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ArmgaSys.ConDoc.Droid.Views.DrawingImageView
android:id="#+id/plan_markup_image"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<SkiaSharp.Views.Android.SKCanvasView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/plan_markup_canvas" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="bottom">
<TextView
android:id="#+id/planMarkupMessage"
android:text="Touch and drag to"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:textColor="#000000"
android:textAlignment="center"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#color/primary_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is my text" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
This is what you want?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
layout="#layout/widget_toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ArmgaSys.ConDoc.Droid.Views.UIColoredSpinner
android:id="#+id/drawing_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:popupTheme="#style/AppTheme.PopupOverlay"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:id="#+id/plan_markup_undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Undo"/>
<Button
android:id="#+id/plan_markup_continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continue"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ArmgaSys.ConDoc.Droid.Views.DrawingImageView
android:id="#+id/plan_markup_image"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<SkiaSharp.Views.Android.SKCanvasView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/plan_markup_canvas" />
<TextView
android:id="#+id/planMarkupMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:gravity="center"
android:text="Touch and drag to"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is my text"/>
</LinearLayout>
</LinearLayout>
I've only put the father match_parent, and I've adjusted LinearLayout child to his father with match_parent.
[EDIT] I added gravity in LinearLayout parent to end and LinearLayout child has wrap_content width.
I have a problem with my XML layout, something that I thought wouldn't give me many problems. I have a layout below in a scroll view, but the bottom of the layout is being cut off, I can't see anything past the second list view. From looking around, I can't seem to see anything wrong with the xml itself and I can't see what I am doing wrong.
I have tried the suggestion to the problem, that is adding a weight to each of the different elements but this still hasnt solved the problem.
I have also added the main activity in which the fragment is placed incase that might help solve the problem
Fragment 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:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Main XML
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout2">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</android.support.design.widget.CoordinatorLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
I solved the issue. As the scroll view was being displayed the bottom was being cut off by the bottom action bar on the actual phone. So to solve this I added padding to the bottom of the scrollview in order to push it back up above the action bar.
The new layout it as follows
Updated working 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:id="#+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical"
android:paddingBottom="?android:attr/actionBarSize"> <<<-------added this line
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/ingredientsHeading"
android:layout_below="#+id/text_input_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Ingredients"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/ingredientsList"
android:layout_below="#+id/ingredientsHeading"
android:layout_above="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Ingredient"
android:id="#+id/addIngredient"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<TextView
android:id="#+id/directionsHeading"
android:layout_below="#+id/addIngredient"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Directions"
android:textStyle="bold|italic"
android:layout_weight="1" />
<ListView
android:id="#+id/directionsList"
android:layout_below="#+id/directionsHeading"
android:layout_width="wrap_content"
android:layout_height="195dp"
android:layout_weight="1"></ListView>
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/addDirection"
android:layout_below="#+id/ingredientsList"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/addDirection">
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/showOptionsDialog"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Add Direction"
android:id="#+id/saveRecipe"
android:enabled="true"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="#+id/showOptionsDialog"
android:layout_weight="1" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/filterButton"
app:backgroundTint="#color/floatingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:clickable="true"
android:src="#drawable/ic_filter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="63dp"
android:layout_marginRight="16dp" />
</android.support.design.widget.CoordinatorLayout>
Add these lines in your ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
use weightSum for all components in your xml file,
It's android:layout_weight. Weight can only be used in LinearLayout. If the orientation of linearlayout is Vertical, then use android:layout_height="0dp" and if the orientation is horizontal, then use android:layout_width = "0dp". It'll work perfectly.
From your question -- bottom of the layout is being cut off
It is because of fixed height given to components.
EDIT -- xml added
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipe Title" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/ingredientsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Ingredients"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/ingredientsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addIngredient"
style="#style/AppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Ingredient" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:orientation="vertical">
<TextView
android:id="#+id/directionsHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Directions"
android:textStyle="bold|italic" />
<ListView
android:id="#+id/directionsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<Button
android:id="#+id/addDirection"
style="#style/AppBaseTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:enabled="true"
android:text="Add Direction" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
You put a weightsum of 1 and your scrollview is 28. You have to put something like that <LinearLayout weightsum=15>(you don't have to put 15) and then what is inside your layout you have to distribute your 15 sum. Like <TextView layout_weight=1> it means that your textview is gonna 1/15. When I use weight I also put the height or the width, depending on which one I want to play, to 0dp. For exemple if I want to play on the width <TextView width=0dp height=wrap_content weight=1>. So you have to give a weight to every child of your LinearLayout.
Hope it help.
Edit: Also ListView in a ScrollView is not a good idea, could come from here. Look this post:
How can I put a ListView into a ScrollView without it collapsing?
I'm trying to use ScrollView and Toolbar as the only childs of LinearLayout but they overlap each other. Searched a bit but didn't find anything useful, any idea how to solve this rather than giving padding/margin to ScrollView?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:float="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="right"
android:background="#color/white_dark_50">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:theme="#style/AppTheme"
android:scrollbarStyle="outsideOverlay"
android:gravity="center_vertical|right"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
>
<!-- -->
</android.support.v7.widget.Toolbar>
<ScrollView
android:scrollbarStyle="outsideOverlay"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="#color/white_dark_50" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="right"
android:background="#color/white_dark_50">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ایجاد جمله جدید"
android:id="#+id/new_sentence_title"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:textStyle="bold"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_colored_doll"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginLeft="25dp"
android:layerType="software"
android:layout_marginRight="25dp"
android:background="#drawable/dashed_line" />
<com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
float:fletPaddingLeft="10dp"
float:fletPaddingRight="10dp"
android:id="#+id/new_sentence_name"
float:fletPadding="10dp">
<EditText
android:layout_marginLeft="10dp"
android:id="#+id/new_sentence_name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme"
android:backgroundTint="#color/accentColor"
android:singleLine="true"
android:textColor="#color/midnight_blue"
android:textColorHint="#color/hintColor"
android:maxLength="20"
android:drawableRight="#drawable/ic_name"
android:gravity="center_vertical|right"
android:hint="عنوان"/>
</com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided>
<com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided
android:layout_width="match_parent"
android:foregroundGravity="center_vertical|right"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
float:fletPaddingLeft="10dp"
float:fletPaddingRight="10dp"
android:id="#+id/new_sentence_period"
float:fletPadding="10dp">
<EditText
android:id="#+id/new_sentence_period_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme"
android:backgroundTint="#color/accentColor"
android:singleLine="true"
android:layout_marginLeft="10dp"
android:inputType="number"
android:textColor="#color/midnight_blue"
android:textColorHint="#color/hintColor"
android:maxLength="20"
android:drawableRight="#drawable/ic_name"
android:gravity="center_vertical|right"
android:hint="دوره تکرار"/>
</com.wrapp.floatlabelededittext.FloatLabeledEditTextRightSided>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<Spinner
android:id="#+id/repeat_kind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/AppTheme"
android:minHeight="25dp"
android:gravity="right"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="نوع تکرار"
android:id="#+id/doll_type_tv"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<com.gc.materialdesign.views.ButtonFlat
android:id="#+id/date_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blue"
android:text="Button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تاریخ تکرار"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<com.gc.materialdesign.views.ButtonFlat
android:id="#+id/time_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/blue"
android:text="Button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="زمان تکرار"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:drawableRight="#drawable/ic_doll"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|right">
<ImageView
android:id="#+id/doll_pic_IV"
android:layout_width="150dp"
android:layout_height="150dp"
style="#style/AppTheme"
android:minHeight="25dp"
android:scaleType="fitXY"
android:gravity="right"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_image_add_to_photos"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="انتخاب صدا"
android:textColor="#color/midnight_blue"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:id="#+id/pic_tv"
android:drawableRight="#drawable/ic_image"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Apparently the problem wasn't overlapping Toolbar with ScrollView, but rather was with ScrollView itself. The problem was arrising from gravity of the only child on ScrollView, so removing gravity from LinearLayout inside ScrollView and the problem was solved. It seems like a bug to me maybe I should contact google and let them know 'bout this.
Try:
<LinearLayout>
<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
This way the LinearLayout is going to firstly compute the dimension of the toolbar, because it has no layout_weight attributes, and lay it down. Then it assigns all the remaining space to the ScrollView.
i solved this by place toolbar and scroll view in relative layout, then give "android:layout_below="#+id/bar" " in scroll view..
just like this:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/bar"
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="?attr/actionBarSize" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar"
android:paddingTop="20dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"/></ScrollView></RelativeLayout>
For my problem: I'm rebuilding an activity into appCompatActivity while using a new standalone toolbar that was being overlapped by a scrollview. My solution was to give the toolbar elevation:
<android.support.v7.widget.Toolbar
...
android:elevation="3dp"
.../>
and increase the margin of the top item in my scrollview.
<EditText
...
android:layout_marginTop="80dp"
.../>
I solved this by adding this with this code, I hope it will help
<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:fillViewport="false"
android:orientation="vertical"
android:padding="#dimen/activity_vertical_margin"
tools:context="tz.co.ikunda.MemberProfileActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
android:orientation="vertical">
<TextView
android:id="#+id/tvMyView"
android:layout_width="match_parent"
android:text="You views goes between this scrollview layout"
android:layout_height="wrap_content" />
</ScrollView>
for me, problem solved simply by put my ScrollView in a Frame layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
......
</ScrollView>
</FrameLayout>
For anyone experiencing similar issue with NestedScrollview, set marginTop of root component to that of actionBarSize, i.e.:
android:layout_marginTop="?attr/actionBarSize"
I would like my button to be at the bottom of my layout but it doesn't seem to be working. Somehow it's stuck at the middle of my screen and it won't go down... code below. My main LinearLayout seems to have a match_parent height though...
<ScrimInsetsScrollView
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="#dimen/navdrawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/navdrawer"
android:background="#color/navdrawer_background"
android:fitsSystemWindows="true"
app:insetForeground="#4000">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/chosen_account_view"
android:layout_width="match_parent"
android:layout_height="#dimen/navdrawer_chosen_account_height"
android:layout_alignParentTop="true">
<!--android:foreground="?photoItemForeground"-->
<!-->-->
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/ic_foodie_nav_image"
android:tint="#color/session_photo_scrim"
android:id="#+id/profile_cover_image"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/keyline_1"
android:paddingRight="#dimen/keyline_1"
android:paddingTop="#dimen/keyline_1"
android:id="#+id/chosen_account_content_view"
android:onClick="showProfile">
<com.pkmmte.view.CircularImageView
android:id="#+id/profile_image"
android:layout_width="#dimen/navdrawer_profile_image_size"
android:layout_height="#dimen/navdrawer_profile_image_size"
android:src="#drawable/ic_action_person"
android:scaleType="centerCrop"
android:layout_marginTop="16dp"
/>
<ImageView
android:id="#+id/expand_account_box_indicator"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_marginLeft="16dp"
android:paddingBottom="16dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:scaleType="center"
android:src="#drawable/ic_drawer_accounts_expand" />
<TextView
android:id="#+id/profile_email_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/profile_image"
android:layout_toLeftOf="#id/expand_account_box_indicator"
android:layout_alignParentBottom="true"
android:paddingBottom="16dp"
android:textSize="#dimen/text_size_medium"
android:textColor="#color/body_text_2_inverse"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"/>
<TextView
android:id="#+id/profile_name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/profile_email_text"
android:layout_alignLeft="#id/profile_image"
android:layout_toLeftOf="#id/expand_account_box_indicator"
android:textSize="#dimen/text_size_large"
android:textColor="#color/body_text_1_inverse"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:textStyle="bold"/>
</RelativeLayout>
</FrameLayout>
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- Account items -->
<LinearLayout
android:id="#+id/account_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical"
android:visibility="invisible" />
<LinearLayout
android:id="#+id/navdrawer_items_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
/>
</FrameLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="#color/red_500"
android:layout_gravity="bottom"
android:gravity="bottom"
/>
</LinearLayout>
</ScrimInsetsScrollView>
The solution is in that post LinearLayout not expanding inside a ScrollView
Found the solution myself in the end. The problem was not with the
LinearLayout, but with the ScrollView (seems weird, considering the
fact that the ScrollView was expanding, while the LinearLayout
wasn't).
The solution was to use android:fillViewport="true" on the ScrollView.
Just use it on the Scrimset