首页 > 解决方案 > 真实RelativeLayout下如何让ScrollView滚动

问题描述

下面的代码是一个XML布局,我试图在图像的Scrollview下方滚动,RelativeLayout图像布局仍然在其位置,但所有布局滚动我该如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" 
    android:layout_width="match_parent"
   android:theme="@style/no_title"
  android:layout_height="match_parent"
  >
    <RelativeLayout
    android:id="@+id/real"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        tools:ignore="MissingPrefix"
        >
            <android.support.design.widget.AppBarLayout

            android:layout_width="match_parent"
            android:layout_height="170dp"
            android:fitsSystemWindows="true">
                <ImageView
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:src="@drawable/person_ic" />
            </android.support.design.widget.AppBarLayout>
            <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@android:drawable/ic_menu_camera"
            app:fabSize="mini"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end" />
        </android.support.design.widget.CoordinatorLayout>
    </RelativeLayout>
    <ScrollView
        android:id="@+id/scroll_info"
          android:layout_width="match_parent"
         android:layout_height="match_parent"
        android:fillViewport="true" >
        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:orientation="vertical">
            <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
                <android.support.design.widget.TextInputLayout
                android:id="@+id/USerNameLayout"  
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="240dp"
                android:textColorHint="#cccccc">
                    <EditText
                    android:id="@+id/NameStudentRe"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="#ffff"
                    android:clickable="true"
                    android:cursorVisible="false"
                    android:drawableLeft="@drawable/ic_person_black_24dp"
                    android:focusable="false"
                    android:focusableInTouchMode="false"
                    android:hint="   Name"
                    android:inputType="textPersonName"
                    android:padding="3dp"
                    android:text=" Sukaina Ahmed Al-Mutawakel"
                    android:textColor="#cccccc"
                    android:textSize="20sp" />
                </android.support.design.widget.TextInputLayout>
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

标签: javaandroidandroid-layout

解决方案


此代码有效。图像布局下的文本视图滚动并且布局不移动。

<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"
tools:context=".MainActivity">


<RelativeLayout
    android:id="@+id/test_stackoverflow"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:background="@color/colorAccent"/>

</RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/test_stackoverflow">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    </ScrollView>


推荐阅读