ScrollView 位于另一个布局之上 Android
ScrollView goes on top of another layout Android
在下面的代码中,我有两个主要容器,一个 RelativeLayout 和一个 ScrollView。我需要 RelativeLayout 固定在顶部,而在其下方我需要带有图像的 ScrollView 可滚动。我有以下两个问题:
- 虽然我的 ScrollView 是可滚动的,但它位于 RelativeLayout 之上。 !重要
我在垂直 LinearLayout 中显示的图像视图是缩略图大小的。如果我有 15-20 张图片,它们会拍摄很多垂直 space。如何根据屏幕尺寸使图像适合一行中的最大值,然后转到下一行?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView>
</ImageView>
<ImageView>
</ImageView>
<ImageView>
</ImageView>
<ImageView>
</ImageView>
</LinearLayout>
</ScrollView>
首先,您可以将 RelativeLayout
的身高设置为固定值。然后将 ScrollView
的高度设置为 match_parent
,这样它就占据了所有可用的 space。那么这两个都应该包含在垂直 LinearLayout
中,以避免任何重叠。
以简单的方式遵循这些:
- 您需要为父项使用固定高度,即
<RelativeLayout>
。
- 将
ScrollView
的高度设置为 match_parent
。
- 确保将所有内容都放在
LinearLayout
中。
最后你会得到这样的结果:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</RelativeLayout>
</LinearLayout>
在下面的代码中,我有两个主要容器,一个 RelativeLayout 和一个 ScrollView。我需要 RelativeLayout 固定在顶部,而在其下方我需要带有图像的 ScrollView 可滚动。我有以下两个问题:
- 虽然我的 ScrollView 是可滚动的,但它位于 RelativeLayout 之上。 !重要
我在垂直 LinearLayout 中显示的图像视图是缩略图大小的。如果我有 15-20 张图片,它们会拍摄很多垂直 space。如何根据屏幕尺寸使图像适合一行中的最大值,然后转到下一行?
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </RelativeLayout> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView> </ImageView> <ImageView> </ImageView> <ImageView> </ImageView> <ImageView> </ImageView> </LinearLayout> </ScrollView>
首先,您可以将 RelativeLayout
的身高设置为固定值。然后将 ScrollView
的高度设置为 match_parent
,这样它就占据了所有可用的 space。那么这两个都应该包含在垂直 LinearLayout
中,以避免任何重叠。
以简单的方式遵循这些:
- 您需要为父项使用固定高度,即
<RelativeLayout>
。 - 将
ScrollView
的高度设置为match_parent
。 - 确保将所有内容都放在
LinearLayout
中。
最后你会得到这样的结果:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</RelativeLayout>
</LinearLayout>