java - 真实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>
解决方案
此代码有效。图像布局下的文本视图滚动并且布局不移动。
<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>
推荐阅读
- javascript - 如果我使用地图而不是静态组件,则路线会重新呈现
- php - 在 Symfony 中而不是在控制器中使用服务的最佳实践是什么?
- c# - SignInManager.PasswordSignIn 在第一次尝试时很慢
- javascript - JavaScript 替换字符串中的特定单词
- sql-server - SQL Server System.OutOfMemoryException
- angular - 在同一项目中的两个 Angular 应用程序之间导航
- java - Spark:高效的行复制
- node.js - MongoError:拓扑被破坏,我该如何修复它?
- python - 正则表达式数字 - Python
- javascript - JavaScript - 修改属性/数据绑定时执行代码