我的问题是当用户进入此屏幕时应该滚动屏幕但有些不滚动?所以这是我的xml代码,在CoordinatorLayout中有滚动视图。
<?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:nestedScrollingEnabled="true"
android:background="@color/main_background_color"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_top_padding">
<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="wrap_content"
android:background="#00000000"
android:elevation="2dp"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="@style/MaxxSports.ToolbarTextAppearance"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="2dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/al_svMainScroll"
android:layout_below="@id/appbar_layout"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/lf_cvInputContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_firstNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp"
android:theme="@style/MaxxSports.TextInputLayout">
<android.support.design.widget.TextInputEditText
style="@style/MaxxSports.EditTextStyle"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_lastNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp"
android:theme="@style/MaxxSports.TextInputLayout">
<android.support.design.widget.TextInputEditText
style="@style/MaxxSports.EditTextStyle"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp"
android:theme="@style/MaxxSports.TextInputLayout">
<android.support.design.widget.TextInputEditText
style="@style/MaxxSports.EditTextStyle"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp"
android:theme="@style/MaxxSports.TextInputLayout">
<android.support.design.widget.TextInputEditText
style="@style/MaxxSports.EditTextStyle"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_confirmPasswordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp"
android:theme="@style/MaxxSports.TextInputLayout">
<android.support.design.widget.TextInputEditText
style="@style/MaxxSports.EditTextStyle"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<!--</android.support.v7.widget.CardView>-->
<Button
android:id="@+id/lf_createAccountButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lf_cvInputContainer"
android:layout_margin="16dp"
android:background="@drawable/sign_in_btn_bg"
android:elevation="5dp"
android:gravity="center"
android:text="Create Account"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
所以在尝试了这么多事情后,仍然没有找到解决方案,任何建议或我错在哪里请告诉我。
答案 0 :(得分:1)
试试这个
<?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:nestedScrollingEnabled="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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="wrap_content"
android:background="#00000000"
android:elevation="2dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="2dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/al_svMainScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/appbar_layout"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/lf_cvInputContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_firstNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_lastNameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/lf_confirmPasswordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:minHeight="72dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<!--</android.support.v7.widget.CardView>-->
<Button
android:id="@+id/lf_createAccountButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lf_cvInputContainer"
android:layout_margin="16dp"
android:elevation="5dp"
android:gravity="center"
android:text="Create Account"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:0)
在使用NestedScrollView
时,您应该使用CoordinatorLayout
,并且您正在使用CoordinatorLayout
的布局行为。如下。..
<android.support.design.widget.CoordinatorLayout
....
...>
<android.support.design.widget.AppBarLayout
....>
</android.support.design.widget.AppBarLayout>
<NestedScrollView
android:id="@+id/al_svMainScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- Your scrollring layout will go here -->
</NestedScrollView>
</android.support.design.widget.CoordinatorLayout>