首页 > 解决方案 > 如何在 Xamarin Android 中剪辑滚动视图的边界

问题描述

我在滚动视图内部的线性布局中有一个图像视图。我无法让 ScrollView 在图像上方和下方停止滚动。我不希望用户能够滚动超出图像的边界。这是我的 XML:

<ScrollView
        android:id="@+id/scrollViewLegend"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:background="@color/Copper"
        android:scrollbars="vertical"
        android:layout_marginTop="2dp"
        >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/legend"
            android:scaleType="fitStart"/>
        </LinearLayout>
    </ScrollView>

任何帮助,将不胜感激。谢谢。

标签: c#androidxmlxamarinandroid-scrollview

解决方案


如果它是一个选项,将 ImageView 的布局高度设置为固定值将解决此问题。

<ImageView
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:src="@drawable/legend"
    android:scaleType="fitStart"/>

推荐阅读