2

我在片段和活动中有一个 NestedScrollview 作为具有折叠工具栏的父级,使用 viewpager,问题是嵌套的滚动视图不会滚动以显示完整的 UI,除非我显示 textinputlayout 错误,

在 textinput 布局出现错误后,视图(按钮)显示活动布局如下,

<?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">

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    style="@style/overscroll_remove"
    android:background="@color/color_white"
    android:paddingLeft="@dimen/dimen_editext_padding"
    android:paddingRight="@dimen/dimen_editext_padding"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


 <android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dimen_collapsing"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            app:tabMode="fixed"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:tabIndicatorColor="@color/color_00cdb"
           app:tabIndicatorHeight="@dimen/dimen_tab_indicator_height"
            app:tabSelectedTextColor="@color/color_2323"/>

        <include layout="@layout/layout_toolbar"
            app:layout_collapseMode="pin" />


    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

viewpager 和 scrollivew 的样式,没有 true 从来没有

这是我的注册屏幕的布局,在 NestedScrollview 里面没有滚动到它的全长,直到 textinputlayout 显示错误,附上截图以供参考&布局如下,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/overscroll_remove"
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/fs_lay_container"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_margin="@dimen/dimen_layout_margin"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/d_drawable_rectangel_box">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_fName"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:tag="@string/s_signup_hint_fName"
                android:drawableLeft="@drawable/di_user_icon"
                android:hint="@string/s_signup_hint_fName" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_lName"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:tag="@string/s_signup_hint_lName"
                android:drawableLeft="@drawable/di_user_icon"
                android:hint="@string/s_signup_hint_lName" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_email"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:tag="@string/s_signup_hint_email"
                android:drawableLeft="@drawable/di_email"
                android:hint="@string/s_signup_hint_email" />

        </android.support.design.widget.TextInputLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical">

            <cl.countrycodepicker.CountryCodePicker
                android:visibility="gone"
                android:id="@+id/fs_tl_ccp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:defaultNameCode="IN" />

            <android.support.design.widget.TextInputLayout
                style="@style/textInputLayout"
                android:id="@+id/fs_tl_countryCode"
                android:clickable="true"
                app:errorTextAppearance="@style/error_appearance"
                app:hintTextAppearance="@style/hint_appearance">

                <android.support.design.widget.TextInputEditText
                    style="@style/edittext"
                    android:id="@+id/fs_ed_countryCode"
                    android:drawableLeft="@drawable/di_mobile"
                    android:clickable="true"
                    android:tag="@string/s_signup_hint_countryCode"
                    android:drawableRight="@drawable/di_drop_down"
                    android:hint="@string/s_signup_hint_countryCode"  />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_phone"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:tag="@string/s_signup_hint_phone"
                android:inputType="number"
                android:maxLength="@integer/s_phone_length"
                android:drawableLeft="@drawable/di_mobile"
                android:hint="@string/s_signup_hint_phone" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_password"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:inputType="textPassword"
                android:tag="@string/s_signup_hint_password"
                android:drawableLeft="@drawable/di_password"
                android:hint="@string/s_signup_hint_password" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_cPassword"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:inputType="textPassword"
                android:drawableLeft="@drawable/di_password"
                android:hint="@string/s_signup_hint_cPassword" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/fs_tl_address"
            style="@style/textInputLayout"
            app:errorTextAppearance="@style/error_appearance"
            app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:tag="@string/s_signup_hint_address"
                android:id="@+id/fs_ed_address"
                android:drawableLeft="@drawable/di_address"
                android:hint="@string/s_signup_hint_address" />
        </android.support.design.widget.TextInputLayout>

        <RelativeLayout android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/fs_tl_promo"
                android:layout_centerVertical="true"
                style="@style/textInputLayout"
                android:layout_toLeftOf="@+id/fs_tv_optional"
                app:errorTextAppearance="@style/error_appearance"
                app:hintTextAppearance="@style/hint_appearance">

            <android.support.design.widget.TextInputEditText
                style="@style/edittext"
                android:imeOptions="actionDone"
                android:id="@+id/fs_ed_promo"
                android:background="@color/color_tranparent"
                android:drawableLeft="@drawable/di_optional"
                android:hint="@string/s_signup_hint_rererral" />
             </android.support.design.widget.TextInputLayout>

            <TextView style="@style/textView"
                android:id="@+id/fs_tv_optional"
                android:paddingTop="@dimen/dimen_drawable_padding"
     android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:layout_alignParentRight="true"
                android:layout_width="wrap_content"
                android:layout_centerVertical="true"
                android:text="@string/s_signup_optional"/>
        </RelativeLayout>
    </LinearLayout>

    <TextView style="@style/textView"
        android:layout_below="@+id/fs_lay_container"
        android:id="@+id/fs_tv_tCondition"
        android:text="@string/s_signup_tCondition"/>

    <Button style="@style/button"
        android:layout_marginTop="@dimen/dimen_layout_margin"
        android:layout_below="@id/fs_tv_tCondition"
        android:id="@+id/fs_bt_save"
        android:text="@string/s_signup"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

TextInput 布局各种样式如下,

    <style name="textInputLayout">
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Subhead</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>

<style name="error_appearance" parent="TextAppearance.AppCompat.Medium">
    <item name="android:textColor">@color/color_red</item>
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Subhead</item>
</style>

<style name="hint_appearance" parent="TextAppearance.AppCompat.Small">
    <item name="android:textColor">@color/color_374</item>
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Subhead</item>
</style>

Edittext样式如下,

    <style name="edittext" parent="Base.Widget.AppCompat.EditText">
    <item name="android:drawablePadding">@dimen/dimen_drawable_padding</item>
    <item name="android:singleLine">true</item>
    <item name="android:padding">@dimen/dimen_editext_padding</item>
    <item name="android:gravity">left</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>

注册布局显示如下,包含一个未在屏幕底部完整显示的按钮 嵌套滚动视图中有一个未完全显示的按钮

4

1 回答 1

0

您可以使用 MyMeasuredViewPager 并使用它来代替您的视图寻呼机

    public class MyMeasuredViewPager extends ViewPager {
    public MyMeasuredViewPager(Context context) {
        super(context);
    }

    public MyMeasuredViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int height = 0;
        for (int i = 0; i < getChildCount(); ++i) {
            View child = getChildAt(i);
            child.measure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            int h = child.getMeasuredHeight();
            if (h > height) {
                height = h;
            }
        }

        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
于 2017-04-27T07:01:32.073 回答