【问题标题】:NestedScrollView incomplete scrollNestedScrollView 不完整滚动
【发布时间】:2018-06-02 10:48:23
【问题描述】:

我正在使用 NestedScrollView 来访问 similar to this

更新

这是我的repo

我知道当手机变成横向滚动时,不要让我看到按钮或底部的灰色视图

这是我的mainlayout.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.support.design.widget.AppBarLayout
        android:id="@+id/appbarLayout"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleTextAppearance="@style/Toolbar.TitleText"
            app:collapsedTitleTextAppearance="@style/Toolbar.TitleText"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/iv_tipo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:fitsSystemWindows="true"
                android:layout_gravity="center"
                app:layout_collapseMode="parallax"
                app:srcCompat="@drawable/aviso_128dp"/>

            <!--<include layout="@layout/toolbar_pin" />-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/myToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

            <TextView
                android:id="@+id/tv_toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

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


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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <!-- A CardView that contains a TextView -->
            <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/card_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="10dp"
                card_view:cardCornerRadius="4dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <include
                        android:id="@+id/field_nombre"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_direccion"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_direccion2"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_localidad"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_provincia"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_telefono"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_email"
                        layout="@layout/actividad_field" />

                    <include layout="@layout/actividad_separator" />

                    <include
                        android:id="@+id/field_descripcion"
                        layout="@layout/actividad_field" />


                </LinearLayout>
            </android.support.v7.widget.CardView>


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/bt_productos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ver productos" />

                <Button
                    android:id="@+id/bt_finalizar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Finalizar" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="20dp"
                android:background="@color/gray"/>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

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

还有actividad_separator.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <View
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="0dp"/>

    <View
        android:layout_width="0dp"
        android:layout_weight="8"
        android:layout_height="1dp"
        android:background="@color/divider"/>

    <View
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="0dp"/>

</LinearLayout>

还有actividad_field.xml

<?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="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal">

    <View
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="0dp"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="8"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/iv_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_person_primary_36dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center">

            <TextView
                android:id="@+id/tv_clave"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:textSize="10sp"
                android:text="Clave" />

            <TextView
                android:id="@+id/tv_valor"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:textStyle="bold"
                android:text="Valor"/>
        </LinearLayout>
    </LinearLayout>

    <View
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="0dp"/>
</LinearLayout>

看起来是这样的:

这就是它的工作原理(滚动不完整,因为我看不到底部的灰色条):

【问题讨论】:

  • 尝试在卷轴底部添加一些空间,我遇到了类似的问题
  • 这就是我添加灰色条的原因。当我运行项目时,我看不到灰色条。
  • 究竟有什么问题?您想完全显示布局底部的按钮,对吗?这就是你要问的问题?请澄清。
  • @ReazMurshed 我写了incomplete scrolling because I cant see the grey bar at the bottom。如果你运行项目(我的 repo 在帖子中),你可以看到滚动没有显示所有子视图。

标签: android material-design android-coordinatorlayout


【解决方案1】:

NestedScrollView里面加android:paddingBottom="50dp"

<LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:paddingBottom="50dp"
     android:orientation="vertical">

【讨论】:

    【解决方案2】:

    NestedScrollView 内,您有一个垂直的LinearLayout。 您需要将其高度更改为wrap_content

    【讨论】:

    • 我试过了,但还是失败了。今天我将尝试上传一个虚拟项目,以便清楚地展示这个问题。
    【解决方案3】:

    我有一个类似的问题,用约束布局替换线性布局并将底部约束添加到该滚动视图的底部并为其添加一些边距对我有用。你可以试试。

    【讨论】:

    • 我会考虑的。但我还不想处理约束布局。
    • 尝试将 translationZ 添加到整个布局中
    • 添加最后一个即可行并检查,如果这不起作用尝试在底部视图中添加它,我想它可能会有所帮助
    • 这很有趣,已经尝试在底部添加一个 dummyview,如果没有添加一个高度为 2-3 dp 的视图并将其放在滚动视图内最底部的视图下方
    【解决方案4】:

    在完成所有布局更改后,我在 Manifest 中进行了一些更改,在活动中添加了 android:configChanges="orientation|screenSize" 并在横向中完美运行

    <activity android:name=".MainActivity"
            android:configChanges="orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>  
    
    
    
    [![Landscape Image][1]][1]
    [1]: https://i.stack.imgur.com/2LHpR.png
    

    【讨论】:

    • 如果你在纵向测试(不改变移动方向)灰色条仍然丢失。
    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    • 2020-06-01
    • 2020-04-28
    相关资源
    最近更新 更多