Android 中 ScrollView 的内容从父视图中泄漏
Contents of ScrollView leaking out of the parent view in Android
下面的布局文件应该给你这样的想法,我想要在 TextView 下面的 RelativeLayout 中滚动视图的内容,但是 ScrollView 的内容离开 RelativeLayout 隐藏在 TextView 后面。我不明白这是怎么回事。在 ScrollView 内的 RelativeLayout 中,我以编程方式添加了一个 LinearLayoutCompat 对象,我也以编程方式向该对象添加了几个 AppCompatTextView 对象。屏幕截图只是布局的 1 个实例。
我将嵌套的 RelativeLayout 设置为从 TextView 下面开始,但它仍然从最上面开始。
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/narrowTextnon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/cherryRed"
android:elevation="8dp"
android:gravity="center"
android:layout_marginTop="15dp"
android:padding="25dp"
android:text="Let's narrow down now !"
android:textColor="@color/wineBrown"
android:textSize="22sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/narrowTextnon"
android:gravity="center">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/dataContnon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
RelativeLayout 的正常行为,我要做的是将根布局更改为 RelativeLayout,并在嵌套的 RelativeLayout 中声明 android:layout_below="@id/narrowText"
我猜你的问题出在这一行:
android:layout_height="match_parent"
这里:<RelativeLayout //To position ScrollView in center
.
在那里尝试 wrap_content
。
终于通过申请得到了我想要的东西:
android:layout_height="match_parent"
到嵌套的 RelativeLayout 以将 ScrollView 定位在中心
android:layout_below="@id/narrowText"
让 ScrollView 从 TextView 下面开始,而不是从最上面开始。
android:layout_alignParentBottom = true
让 ScrollView 从 TextView 的底部延伸到屏幕的底部。
下面的布局文件应该给你这样的想法,我想要在 TextView 下面的 RelativeLayout 中滚动视图的内容,但是 ScrollView 的内容离开 RelativeLayout 隐藏在 TextView 后面。我不明白这是怎么回事。在 ScrollView 内的 RelativeLayout 中,我以编程方式添加了一个 LinearLayoutCompat 对象,我也以编程方式向该对象添加了几个 AppCompatTextView 对象。屏幕截图只是布局的 1 个实例。
我将嵌套的 RelativeLayout 设置为从 TextView 下面开始,但它仍然从最上面开始。
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/narrowTextnon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/cherryRed"
android:elevation="8dp"
android:gravity="center"
android:layout_marginTop="15dp"
android:padding="25dp"
android:text="Let's narrow down now !"
android:textColor="@color/wineBrown"
android:textSize="22sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/narrowTextnon"
android:gravity="center">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/dataContnon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
RelativeLayout 的正常行为,我要做的是将根布局更改为 RelativeLayout,并在嵌套的 RelativeLayout 中声明 android:layout_below="@id/narrowText"
我猜你的问题出在这一行:
android:layout_height="match_parent"
这里:<RelativeLayout //To position ScrollView in center
.
在那里尝试 wrap_content
。
终于通过申请得到了我想要的东西:
android:layout_height="match_parent"
到嵌套的 RelativeLayout 以将 ScrollView 定位在中心
android:layout_below="@id/narrowText"
让 ScrollView 从 TextView 下面开始,而不是从最上面开始。
android:layout_alignParentBottom = true
让 ScrollView 从 TextView 的底部延伸到屏幕的底部。