2012-07-26 80 views
26

我有一个具有相关布局的根scrollview元素和相对布局中的一堆表单元素。Android ScrollView拒绝滚动到底部

出于某种原因,当软键盘向上时,似乎无法一直滚动到底部,这会将我的一个按钮切成两半。

下面是层次结构查看器的截图,用于说明我的意思。

enter image description here

正如你所看到的,系统知道该视图延续了以往的键盘,但滚动视图(其正确填写屏幕的可见部分)将不会继续,因为它应该向下滚动。

我有android:windowSoftInputMode="adjustResize"在活动的清单中,我可以/不会将它切换为平移。

任何帮助表示赞赏。

编辑:我看到这在多个视图。下面是同样的问题,另一种观点的XML:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/background" > 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="32dp" > 
     <EditText 
      android:id="@+id/reset_oldpass" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:ems="10" 
      android:singleLine="true" 
      android:hint="@string/current_password" 
      android:layout_marginTop="16dp" /> 
     <EditText 
      android:id="@+id/reset_pass1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/reset_oldpass" 
      android:ems="10" 
      android:hint="@string/reset_new_pass" 
      android:inputType="textPassword" 
      android:layout_marginTop="16dp" /> 
     <EditText 
      android:id="@+id/reset_pass2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/reset_pass1" 
      android:ems="10" 
      android:hint="@string/reset_confirm_pass" 
      android:inputType="textPassword" 
      android:layout_marginTop="16dp" /> 
     <TextView 
      android:id="@+id/reset_forgot_password" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/reset_pass2" 
      android:layout_marginTop="16dp" 
      android:textColor="@color/Link" 
      android:textStyle="bold" 
      android:text="@string/Login_forgot_password" /> 
     <Button 
      android:id="@+id/reset_reset_password_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/reset_forgot_password" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="16dp" 
      android:layout_marginBottom="32dp" 
      android:text="@string/reset_change_pass" /> 
    </RelativeLayout> 
</ScrollView> 
+0

这也发生在LinearLayout中。感谢您提供此线程! – avalancha 2015-11-09 08:42:55

回答

39

这确实是奇怪,但它似乎是由android:layout_margin="32dp"的RelativeLayout的内造成的。一旦我把它拿出来,滚动工作正常。

当然,正因为如此,我不得不为表单元素添加更多的边距,但至少现在已经修复了。

+3

这是真的。如果您的ScrollView中的布局具有边距,您将无法一直滚动到底部。对于我的情况,我可以将边距放在根布局中,因为我有一个包含滚动视图和按钮的LinearLayout。 – slott 2013-11-24 09:03:48

+0

感谢您的自动回复,它为我节省了很多时间! – Apollo 2014-10-15 07:49:46

+0

滚动视图上的填充将防止需要保证每个元素? – Gulfaran 2016-03-02 16:59:13

13

我有同样的问题,我通过在ScrollView中使用填充而不是在RelativeLayout中使用边距来修复它。

因此,从RelativeLayout(ScrollView的子项)中删除android:layout_margin="32dp"并将android:padding="32dp"添加到ScrollView。

+0

这是比较合适的解决方案,而不是去分割子元素的边距。边缘只需放置在适当的位置; ScrollView本身,而不是它周围的布局元素。 – 2013-10-24 13:49:17

+0

只是这样说,没有注意到这个帖子的评论或日期xD – Gulfaran 2016-03-02 16:59:51

+0

如果这有助于其他人,当我将填充放在ScrollView上时,我也遇到了这个错误。唯一对我有用的是在ScrollView的孩子身上填充填充。 – 2016-07-01 20:25:36

0

您还可以插入假以模仿底边距是这样的:

<View 
      android:layout_width="match_parent" 
      android:layout_height="20dp" 
      android:layout_below="@id/recompensaLabel" 
      android:layout_marginTop="0dp" 
      android:id="@+id/simulate_bottom_margin_view" 

      /> 

的效果是一样的,你只需要插入它的最后一个元素下方的相对布局。

0

我刚刚遇到了一个应用程序的问题,并发现这是由于ScrollView layout_height被设置为包装内容。问题是,如果你有足够的内容需要一个ScrollView,你不想包装内容,因为ScrollView的底部离开屏幕的任意数量。我没有足够的数据受此影响,因为在弹出键盘之前我不需要ScrollView。从外观来看,OP的情况相同。

现在,一旦弹出键盘,ScrollView的底部被抬起的数量与键盘的高度相同,并在键盘的顶部下方以与底部下方相同的任意数量结束可见的屏幕。

最终,我的修复是将ScrollView的顶部绑定到我的工具栏,然后右键单击树中的ScrollVIew并选择“垂直居中”(不在父项中)。现在就像一个魅力。 layout_height应该自动转到0dp。

0

使状态栏在棒棒糖和上面显示为透明,这对我造成了问题。将

android:fitsSystemWindows="true"
设置为包含scrollView的布局的父视图解决了问题。

相关问题