如何将多个图像(ImageView)放入 ScrollView?

How do i put multiple images(ImageView) in a ScrollView?

我想放置多张图片并向下滚动并查看所有图片。我试图将 ScrollView 和 ImageView 放入其中,但我不知道是否需要放置布局。我搜索了教程,但没有找到我需要的内容。

这显然不是 ScrollView 的工作方式。 ScrollView 是一个 ViewGroup,所以你必须把它 放在你想要滚动的视图之外

另外,滚动视图的直接子视图只能有一个。所以你不能这样做:

<ScrollView>
    <ImageView>
    <ImageView>
    <ImageView>
</ScrollView>

实际上,您应该将图像放在 LinearLayout 中,并将 LinearLayout 放在滚动视图中。

<ScrollView>
    <LinearLayout>
        <ImageView>
        <ImageView>
        <ImageView>
    </LinearLayout>
</ScrollView>

注:因为我懒,属性省略了:P

编辑:

如果要向下滚动,只需将 orientation 属性设置为 "vertical"

<ScrollView>
    <LinearLayout
        android:orientation="vertical"
        other attributes.../>
            image views here...
    </LinearLayout
</ScrollView>

查看 CardView 的 Android 文档 http://developer.android.com/training/material/lists-cards.html

您可以在每个 CardView 元素中放置一个图像,并在图像下方放置一个共享按钮。正如我之前所说,在处理图像时必须进行良好的内存管理,而 RecyclerView 将工作得很好。

干杯

试试这个方法

<ScrollView>
<LinearLayout>
    <ImageView>
    <ImageView>
    <ImageView>
    <ImageView>
    <ImageView>
</LinearLayout>
</ScrollView>