状态栏始终在屏幕上

时间:2013-03-13 20:12:52

标签: android android-softkeyboard

美好的一天(或晚上或晚上) 我正在为Android开发一个应用程序,我对一件事非常好奇。我有一个活动,用户与另一个人聊天,比如“即时”聊天。底部有一个EditText,顶部有一些操作栏。我需要的是当用户输入消息并且软件键盘在屏幕上时,我的活动应该向上移动,但操作栏仍应“粘在”屏幕顶部,因为它有一些有价值的控件。 同样,这不是ActionBar,而只是父垂直线性布局中的48dp高度布局。所以我需要知道,当布局离开屏幕时,有一种简单的方法可以防止它移动到顶部。 我试图将所有内容放在FrameLayout中并将此栏放在它上面,但是在键盘打开时它也会离开屏幕......

4 个答案:

答案 0 :(得分:0)

在AndroidManifest上你的活动你应该把它:android:windowSoftInputMode =“adjustResize”

答案 1 :(得分:0)

使用类似的东西:

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

    <com.myapp.MyActionBar
        android:layout_width="match_parent"
        android:layout_height="48dp"/>

    <LinearLayout
        android:id="@+id/mylayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1dp"/>

    <!-- Add your edittext and button -->

</LinearLayout>

这将确保操作栏和edittext +按钮全部在屏幕上,mylayout占据屏幕的其余部分。当您的键盘显示时,mylayout将缩小。

答案 2 :(得分:0)

尝试将android:windowSoftInputMode =“adjustResize”添加到清单中的活动。这告诉Android在键盘出现时完全调整布局大小,而不是平移它。请注意,如果整个布局没有足够的空间,这仍然无效。但是如果您的顶级布局是RelativeLayout,则应该能够使其工作,编辑文本设置为对齐底部,顶部栏对齐顶部,中间部分设置为fill_parent并位于编辑文本上方且位于杆

答案 3 :(得分:0)

使用RelativeLayout作为您的基本布局,并将android:layout_alignParentTop =“true”添加到您的操作栏以保持它

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/action_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:layout_alignParentTop="true" >
    </LinearLayout>

    <TextView
        android:id="@+id/text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>