Android 如果内部布局有边距,则scrollview不工作
我在ScrollView中遇到了一些奇怪的问题,它包含一个带有topMargin的relativeLayoutAndroid 如果内部布局有边距,则scrollview不工作,android,android-layout,scrollview,Android,Android Layout,Scrollview,我在ScrollView中遇到了一些奇怪的问题,它包含一个带有topMargin的relativeLayout <ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="beforeDescendants" andro
<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_编辑器_布局)上方。它看起来是这样的:
<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) 为您的滚动视图提供页边距上边距,因为滚动视图中不需要该空间。如果要进行某种类型的overscroll,则需要对ScrollView进行子类化
希望这对您有所帮助:)我不理解topMargin停止滚动的问题。但是,为了获得所需的边距并保持滚动功能,我可以想到两种解决方案: 1) 添加一个与所需边距高度相同的外部视图,并将其置于相对布局(cp_编辑器_布局)上方。它看起来是这样的:
<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) 为您的滚动视图提供页边距上边距,因为滚动视图中不需要该空间。如果要进行某种类型的overscroll,则需要对ScrollView进行子类化
希望这对您有所帮助:)您的第一个解决方案(添加视图)实际上就是我所做的。您的第二个解决方案因过度滚动而无效。有很多方法可以解决这个问题。我想知道的是为什么这甚至是个问题。但是谢谢你的帮助。顺便说一句,你的解决方案不起作用。您必须在LinerLayout或其他布局中换行视图和相对视图,因为SCrollView只能有一个子视图。另外,我想补充一点,这个解决方案增加了大量不必要的复杂性。现在我有了4个布局的深度。您是另一个需要的包装器。我同意这不是最优雅的解决方案,但至少它确实有效。很抱歉,我无法提供更多帮助。您的第一个解决方案(添加视图)实际上就是我所做的。您的第二个解决方案因过度滚动而无效。有很多方法可以解决这个问题。我想知道的是为什么这甚至是个问题。但是谢谢你的帮助。顺便说一句,你的解决方案不起作用。您必须在LinerLayout或其他布局中换行视图和相对视图,因为SCrollView只能有一个子视图。另外,我想补充一点,这个解决方案增加了大量不必要的复杂性。现在我有了4个布局的深度。您是另一个需要的包装器。我同意这不是最优雅的解决方案,但至少它确实有效。对不起,我不能再帮你了。