繁体   English   中英

ScrollView在协调器和相对布局中不起作用

[英]ScrollView not working within Coordinator and Relative layout

以下代码仅在ScrollView显示4个Editext中的3个。 问题是最后一个EditextButton重叠

为什么ScrollView无法正常工作?

或如何避免这种重叠?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.CoordinatorLayout
    android:id="@+id/cl"
    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_above="@+id/bt_next">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_alignParentTop="true">

        <TextView
            android:id="@+id/tv_activity_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#fff"
            android:textSize="24sp"
            android:text="@string/app_name"/>

        </android.support.v7.widget.Toolbar>

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


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/mysv">


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

            <EditText
                android:id="@+id/et_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 1"/>


            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 2"/>

            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 3"/>

            <View android:layout_width="match_parent" android:layout_height="150dp" />

            <EditText
                android:id="@+id/et_4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 4"/>

        </LinearLayout>

    </ScrollView>

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

<Button
    android:id="@+id/bt_next"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Next"/>

这就是滚动结束时的样子。

在此处输入图片说明

您的问题不是ScrollView,而是您的Button本身在CoordinatorLayout之外浮动。 如果您试图将内容显示在按钮上方,则可以尝试添加alignToTopOf="@id/bt_next (我忘记了属性的确切名称,但是您知道了)。然后协调器应该位于按钮。

如果这不是您要尝试的操作,请发布您要尝试获得的屏幕截图以及现在发生的问题的屏幕截图。

我已经解决了在内部使用NestedlayoutLinearLayout 关键是要记住CoordinatorLayout用作FrameLayout

我发现的唯一问题是滚动时工具栏没有隐藏。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/cl"
        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_above="@+id/bt_next"
        android:layout_alignParentTop="true">

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



        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/mysv">


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways">

            <TextView
                android:id="@+id/tv_activity_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#fff"
                android:textSize="24sp"
                android:text="@string/app_name"/>

            </android.support.v7.widget.Toolbar>

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


        <android.support.v4.widget.NestedScrollView
            android:id="@+id/mysv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


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

                <EditText
                    android:id="@+id/et_1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 1"/>


                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 2"/>

                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 3"/>

                <View android:layout_width="match_parent" android:layout_height="150dp" />

                <EditText
                    android:id="@+id/et_4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Input 4"/>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>
        </LinearLayout>

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

    <Button
        android:id="@+id/bt_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Next"/>


</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM