【发布时间】:2012-10-09 11:29:04
【问题描述】:
我对 ScrollViews 中的 EditText 滚动行为有问题,通常如果键盘在其上打开,它会向上滚动滚动内的内容。但是如果你动态填充滚动视图内的布局,键盘向上推整个屏幕,其他人之前都遇到过这个问题。 提前致谢。
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header_area" >
<LinearLayout
android:id="@+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
此示例在滚动视图中正常工作,线性布局滚动,但即使键盘关闭也显示滚动。我不能使用固定高度。
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_below="@+id/header_area" >
<LinearLayout
android:id="@+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
我在下面尝试了 xml,它在新项目中按预期工作,但在我的项目中推高了窗口。我发现其他一些人遇到了这个问题,我会尽快分享解决方案。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/header_area"
android:layout_width="match_parent"
android:layout_height="50dip" >
</RelativeLayout>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/contentHolder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
【问题讨论】:
-
您是否在 LinearLayout 中添加新视图,父视图是 ScrollView?
-
是的,在scrollView中使用linearLayout。将视图推送到 @+id/contentHolder
-
您在 LinearLayout 右侧有多个 EditText。能否请您显示问题的屏幕截图。
-
无法分享屏幕截图,但添加了新布局。顺便说一句,找到了问题,这一切都与全屏主题有关。感谢您的回复。
-
是的,Android 现在仍然支持 Activity 全屏时软键盘调整大小。
标签: android android-edittext android-scrollview