【问题标题】:ScrollView goes on top of another layout AndroidScrollView 位于另一个布局 Android 之上
【发布时间】:2015-02-18 20:29:42
【问题描述】:

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

  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>
    

【问题讨论】:

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


    【解决方案1】:

    以简单的方式遵循这些:

    1. 您需要为父级使用固定高度,即&lt;RelativeLayout&gt;
    2. ScrollView的高度设置为match_parent
    3. 确保将所有内容都放在 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>
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-26
        • 2021-09-23
        • 2018-01-09
        • 1970-01-01
        • 1970-01-01
        • 2015-10-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多