Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView Overlaps Toolbar

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>

like image 240
M. Erfan Mowlaei Avatar asked May 22 '15 21:05

M. Erfan Mowlaei


Video Answer


2 Answers

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.

like image 200
2 revs Avatar answered Oct 13 '22 12:10

2 revs


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.

like image 41
natario Avatar answered Oct 13 '22 12:10

natario