0%

Android解决软键盘弹出将整个界面包括Actionbar往上顶的问题

之前在项目中遇到一个问题,在一个含有Listview的界面底部的EditText弹出软键盘时会将整个界面包括Actionbar往上顶的蛋疼问题。
很蛋疼的问题,当时试了很多种解决办法,也在网上找了很多办法。修改android:windowSoftInputMode属性值、调整布局甚至将布局调整到跟另外一个效果正常的项目一样的布局也还是没解决这个问题。最后没办法赶项目在不影响功能的正常使用下就先那样了。
今天在无意中浏览stackoverflow网站的时候看到一个在使用Recyclerview的时候遇到一个同样的问题,解决办法是在布局的顶部添加一个空的Scrollview实现了不将Actionbar往上顶的效果。于是赶紧打开之前的项目找到布局文件在顶部添加了一个空的Scrollview。

1
2
3
4
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>

运行看一下效果,果然有效。终于解决了这个蛋疼的问题,记录一下。

http://stackoverflow.com/questions/27212580/recyclerview-hides-actionbar-when-softkeyboard-is-opened

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context="me.drakeet.seashell.ui.social.PostActivity">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>

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

<me.drakeet.seashell.widget.MultiSwipeRefreshLayout
android:layout_weight="1"
android:layout_marginBottom="4dp"
android:id="@+id/swipe_refresh_layout"
style="@style/BbsBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_reply_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"/>

</me.drakeet.seashell.widget.MultiSwipeRefreshLayout>

<include
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/view_reply"/>
</LinearLayout>

</FrameLayout>
 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!