繁体   English   中英

如果内部布局具有边距,则scrollview不起作用

[英]scrollview not working if inside layout has margin

我在ScrollView中遇到了奇怪的问题,其中包含带有topMargin的relativeLayout

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:fillViewport="true"
    android:focusableInTouchMode="true">

    <RelativeLayout
        android:id="@+id/cp_editor_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:layout_marginTop="270dp"
        >
    ...

此代码示例不起作用。 滚动大约20像素后停止。 如果我要删除margin_top属性,则滚动将按预期进行。

谢谢你的帮助

我不了解topMargin停止滚动的问题。 但是,要获得所需的边距并保持滚动功能,我可以想到两种解决方案:

1)添加一个具有与所需边距相同高度的无关视图,并将其置于相对布局(cp_editor_layout)上方。 它看起来像这样:

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:fillViewport="true"
    android:focusableInTouchMode="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <View
            android:layout_width="match_parent"
            android:layout_height="270dp" />

        <RelativeLayout
            android:id="@+id/cp_editor_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white" >

        </RelativeLayout>

    </LinearLayout>

2)给您的滚动视图以margin top margin,因为无论如何滚动空间都不需要。 如果您打算进行某种类型的过度滚动,则需要将ScrollView子类化。

希望这可以对您有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM