在包含 ScrollView 的活动中强制执行adjustPan
Posted
技术标签:
【中文标题】在包含 ScrollView 的活动中强制执行adjustPan【英文标题】:Forcing adjustPan in activity containing ScrollView 【发布时间】:2011-09-01 04:21:12 【问题描述】:我的布局是这样的:
<RelativeLayout>
<RelativeLayout>
</RelativeLayout>
<ViewFlipper>
<ScrollView>
<LinearLayout>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<RelativeLayout>
</RelativeLayout>
</RelativeLayout>
当关注中间的 EditText 时,软键盘按预期弹出,但它总是调整布局大小,即使我在清单中有 android:windowSoftInputMode="adjustPan"
。
调整大小的问题是只有ScrollView缩小了,它上面和下面的RelativeLayouts完好无损,这几乎可以完全掩盖EditText。
我尝试在显示键盘时隐藏RelativeLayouts(这是另一个悲伤的故事),但adjustPan 听起来更合适。但是,它对此活动没有影响。
尽管存在 ScrollView,我如何强制 adjustPan 工作?
更新:
所以不会让我回答我自己的问题,但解决方案是在 ScrollView 上设置 android:isScrollContainer="false"
。
【问题讨论】:
这为我节省了大量时间。非常感谢! 【参考方案1】:好问题大多数开发人员都在做同样的事情,但这不是您需要做的正确方法。这将对您有所帮助。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:orientation="vertical">
<ViewFlipper>
<ScrollView
android:layout_
android:layout_
>
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical"
>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<LinearLayout>
您应该将 LinearLayout 的方向设置为垂直或水平视图,而您从未创建过调整问题。这很简单。
【讨论】:
【参考方案2】:在你的清单的活动标签中试试这个:
android:windowSoftInputMode="stateVisible|adjustPan"
【讨论】:
根据 android 文档,您不应该同时使用 adjustResize 和 adjustPan 标签。它应该是其中之一。以上是关于在包含 ScrollView 的活动中强制执行adjustPan的主要内容,如果未能解决你的问题,请参考以下文章