我有一个RelativeView中的对齐底部属性集的几个元素,当软键盘出现时,元素被软键盘隐藏。显示软键盘时向上移动布局?
我希望它们向上移动,以便如果屏幕空间足够,它们会显示在键盘上方,或者使键盘上方的部分可滚动,以便用户仍然可以看到元素。
关于如何解决这个问题的任何想法?
我有一个RelativeView中的对齐底部属性集的几个元素,当软键盘出现时,元素被软键盘隐藏。显示软键盘时向上移动布局?
我希望它们向上移动,以便如果屏幕空间足够,它们会显示在键盘上方,或者使键盘上方的部分可滚动,以便用户仍然可以看到元素。
关于如何解决这个问题的任何想法?
是的,请查看this article on the Android developers' site,它描述了框架如何处理软键盘的出现。
的android:windowSoftInputMode
属性可以用来指定对每个活动的基础上发生的事情:布局是否调整大小或是否滚动等
您还可以在onCreate()
方法使用此代码:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
谢谢。它拯救了我的一天。 –
对我来说,即使我设置adjustPan screnn只能移动到我点击的编辑文本,但不是整个布局 – murt
添加在AndroidManifest.xml你的活动:
android:windowSoftInputMode="adjustPan|adjustResize"
根据文档,如果您在这里使用两个“调整...”标志,行为是未指定的。看到http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft – user1806772
让你的清单文件,如活性的变化
windowSoftInputMode="adjustResize"
OR
请在活动课中你onCreate()
方法更改,如
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
我已经找到了解决自己的问题,它是和你一样漂亮。
首先,我只有一个带2个元素的LinearLayout,一个ImageView和一个LinearLayout,它包含2个EditText和一个Button,所以我需要让它们在没有键盘的情况下全屏分开,当键盘出现时它们应该看得更近。
因此,我添加了它们之间的视图与0dp和重量1中的高度属性,这让我保持我的视图彼此分离。当键盘出现时,因为它们没有固定高度,所以它们只是调整大小并保持方面。
瞧!当键盘存在或不存在时,布局调整大小和我的视图之间的距离相同。
这里充满清单代码
<activity
android:name=".activities.MainActivity"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
类似的问题,我与我的布局,其由内滚动视图面对的问题。 每当我尝试的EditText来选择文本,复制/剪切/粘贴操作栏被移到了下面的代码本身不调整布局
android:windowSoftInputMode="adjustPan"
通过将其修改为以下
1)AndroidManifest .xml
android:windowSoftInputMode="stateVisible|adjustResize"
2)样式。xml文件中,动作风格
<item name="android:windowActionBarOverlay">true</item>
它的工作。!!!!!!!!!!!!
Thnx解决了我的问题 – Android
绝对的传奇! –
我尝试了迭戈拉米雷斯的方法,它的工作原理。 在AndroidManifest:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
...
</activity>
activity_main.xml中:
<LinearLayout ...
android:orientation="vertical">
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<EditText
android:id="@+id/edName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/first_name"
android:inputType="textPersonName" />
<EditText ...>
...
</LinearLayout>
在其OnCreate中梅索德插入件之下线
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
活性和在其onCreate方法片段
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
在AndroidManifest.xml中,不要忘了设置:
android:windowSoftInputMode="adjustResize"
和内部滚动型的RelativeLayout,设置:
android:layout_gravity="center" or android:layout_gravity="bottom"
一切都会好的
感谢它为我工作 –
android:layout_gravity =“center”工作过,谢谢! :)现在EditText按照我想要的在键盘上移动 –
有3个步骤来向上滚动屏幕。
机器人:windowSoftInputMode = “adjustResize”
getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:background="@drawable/bg" android:layout_height="match_parent" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_gravity="center" > <TextView /> ......... <TextView /> <EditText > <requestFocus /> </EditText> <Button /> </RelativeLayout> </ScrollView>
P.S.不要忘记在父亲相对布局中添加android:layout_gravity =“center”。
,如果你在碎片,那么你必须在下面的代码添加到您的onCreate您的活动能解决问题,我
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
从[Android开发者博客(HTTP
更新参考:// Android的开发者.blogspot.in/2009/04/updating-applications-for-on-screen.html) – Jayabal
@Dinedal你是如何将bottom属性对齐到你的RelativeView? – KJEjava48