我的应用程序是一个聊天应用程序,它的 UI 是:
应用程序的标题
列表视图
聊天消息、输入框和发送按钮
但问题是当我单击编辑文本时,软键盘会出现并将所有内容向上推,但我需要标题留在屏幕上。我已经把它贴简化问题的图像和UI代码这里。(我不能在这篇文章中发布多个链接或图片,因为我是 Stack Overflow 的新手。)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:text="Header contents" android:layout_width="fill_parent"
android:textSize="20sp" android:gravity="center_horizontal"
android:layout_height="wrap_content" />
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" />
<EditText android:text="" android:layout_gravity="bottom"
android:id="@+id/EditText01" android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Android 在默认消息应用程序中有此要求。
有没有人有任何想法?
这个问题很老了,但无论如何 - 解决这个问题的一种方法是将标题下方的所有内容放入 ScrollView 中。
例子:
<!-- Both elements below are children of a parent RelativeLayout -->
<RelativeLayout
android:id="@+id/custom_action_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:isScrollContainer="false" >
<!-- Header goes here. -->
<!-- This part remains fixed even with the keypad popping up. -->
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/custom_action_bar"
android:isScrollContainer="true" >
<!-- Rest of the UI -->
<!-- This part scrolls to accommodate the keyboard -->
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5348 次 |
最近记录: |