I'm trying to learn <CoordinatorLayout>
. I created floating labels for few <EditText>
too, which worked well. But as my views increased I wanted to have a scrolling functionality. Enough searching about the same made it clear that traditional <ScrollView>
doesn't work with <CoordinatorLayout>
. We have to use something called as <NestedScrollView>
I tried using both ScrollView and NestedScrollView but when I used them, all my views jammed up to the top part of the view as shown in the image below:
Upon execution the result remained same. My xml file is added below:
<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_height="match_parent"
android:layout_width="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.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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true"/>
<android.support.design.widget.TextInputLayout
style="@style/fontStyle"
android:id="@+id/input_layout_SignupMail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editSignupEmail"
android:textSize="15dp"
android:hint="@string/email"
android:singleLine="true"
android:lines="1"
android:maxLength="64"
android:drawableLeft="@drawable/mail_id"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
style="@style/fontStyle"
android:id="@+id/input_layout_SignupLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/input_layout_SignupMail">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:id="@+id/editSignupLastName"
android:hint="@string/LastName"
android:singleLine="true"
android:lines="1"
android:maxLength="64"
android:drawableLeft="@drawable/blank"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
style="@style/fontStyle"
android:id="@+id/input_layout_SignupFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/input_layout_SignupLastName">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:id="@+id/editSignupFirstName"
android:hint="@string/FirstName"
android:singleLine="true"
android:lines="1"
android:maxLength="64"
android:drawableLeft="@drawable/blank"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
style="@style/fontStyle"
android:id="@+id/input_layout_SignupPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/input_layout_SignupMail">
<EditText
android:id="@+id/editSignupPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/SignPassword"
android:textSize="15dp"
android:singleLine="true"
android:lines="1"
android:maxLength="64"
android:drawableLeft="@drawable/password"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
style="@style/fontStyle"
android:id="@+id/input_layout_SignupConfPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/input_layout_SignupPassword">
<EditText
android:id="@+id/editSignupConfPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ConfirmPassword"
android:textSize="15dp"
android:singleLine="true"
android:lines="1"
android:maxLength="64"
android:drawableLeft="@drawable/confpassword"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/btnSubmitSignup"
android:text="@string/signup"
android:fontFamily="sans-serif-medium"
android:textStyle="bold"
android:textSize="15dp"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:background="@drawable/button_click_effect"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
When I remove <NestedScrollView>
the output is just fine but without scrolling
I might've done something which triggered this behavior. It's just that I haven't been able to point it out. Been struggling with it since yesterday. Any help could be appreciated
答案 0 :(得分:0)
I'm fairly confident that ScrollView works with CoordinatorLayout or anything else in general. The only catch is that ScrollView expects itself to be the parent. If you can't have it as the parent, then use NestedScrollView.
To fix your problem, you probably need to remove the RelativeLayout and replace it with some other layout, like LinearLayout.