ScrollView位于Android的另一个布局之上

时间:2015-02-18 20:29:42

标签: android android-layout scrollview android-imageview android-scrollview

在下面的代码中,我有两个主容器,一个RelativeLayout和一个ScrollView。我需要将RelativeLayout置于顶部固定的下方,我需要ScrollView,其中Images可以滚动。我有以下两个问题:

  1. 虽然我的ScrollView是可滚动的,但它位于RelativeLayout之上。 !重要
  2. 垂直LinearLayout中显示的图像视图是缩略图大小。如果我有15-20张图像,它们会占用很多垂直空间。如何根据屏幕大小使图像最大化,然后转到下一行?

    <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>
    

2 个答案:

答案 0 :(得分:3)

以简单的方式遵循这些:

  1. 您需要为父级使用固定高度,即<RelativeLayout>
  2. ScrollView的高度设置为match_parent
  3. 确保将所有内容都放在LinearLayout
  4. 最后你会得到这个:

    <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>
    

答案 1 :(得分:1)

首先,您可以将RelativeLayout的高度设置为固定值。然后将ScrollView的高度设置为match_parent,以便占用所有可用空间。然后,这两个都应该包含在垂直LinearLayout中,以避免任何重叠。